# Scans

A scan runs a pipeline of engines against one target: the crawler maps
the application, then the signature engine sends the checks described by
signatures and records a finding for every match. Scans run inside the
backend, stay inside the vault's scope and report their progress live.
This guide covers starting a scan, its options and lifecycle, and the
signature library it draws from.

## Start a scan

Start a scan from a target's page or the **Scans** page, or with
`POST /api/v1/vaults/{vault_id}/scans`:

```json
{
  "target_id": 4,
  "url": "https://app.example.com/",
  "config": {
    "engines": ["crawler", "signature"],
    "crawl": { "depth": 3, "max_pages": 100 },
    "signatures": { "tags": ["sqli"], "severities": ["high", "critical"] },
    "http": { "concurrency": 10, "timeout": 15, "follow_redirects": false }
  }
}
```

Before anything is queued the backend checks that the target belongs to
the vault and is not a wildcard, that the start URL is in the vault's
scope, and that every engine exists. Every request an engine sends is
checked against the scope again, and upstream certificates are verified
under the same policy as the proxy.

| Option | Default | Meaning |
|---|---|---|
| `engines` | `crawler`, `signature` | The pipeline, in order (`GET /api/v1/engines` lists what is installed) |
| `crawl.depth` | `3` (0 to 10) | Link depth from the start URL |
| `crawl.max_pages` | `100` (1 to 5000) | Pages the crawler visits at most |
| `crawl.api_metadata` | `true` | Also ask for an API description at the usual locations (three GET requests) |
| `signatures.ids`, `tags`, `severities` | all active | Which signatures run; empty lists mean every active signature |
| `http.concurrency` | `10` (1 to 200) | Parallel requests |
| `http.timeout` | `15` s (1 to 300) | Per request |
| `http.follow_redirects` | `false` | Follow redirects |
| `http.record_history` | `false` | Keep the requests the scan sends in the HTTP history, see below |
| `http.headers` | none | Extra headers on every request, for example an authorization header. A scan given a session this way (`Authorization` or `Cookie`) stops with the reason after 25 answers in a row of 401, 407, 419 or 440, instead of going on with a session that is no longer accepted |
| `http.session_profile_id` | none | Sign in as one of the vault's [session accounts](session-profiles.md): every request carries the account's headers and the cookies of its jar that match the request, like a Repeater send; `http.headers` are added on top. If the site keeps refusing it (as above) the scan stops and the account is marked expired. **Sign in as** in the new-scan form. Not available for scans on an execution environment |

### Defaults

**Settings › Scans** sets what a new scan starts from: engines, signature
severities and tags, crawl depth and page limit, parallel requests,
timeout, redirects and recording in history. The new-scan form opens with
these values (with the engines of the scan being run again, for **Run
again…**), and a scan started through the API or by an agent without a
`config` uses them as saved. A scan that sends a `config` uses exactly
that. Session accounts and extra headers are chosen per scan and are never
part of the defaults. Only you can change them
(`GET` / `PUT /api/v1/scan-defaults`).

### Requests in history

With **Record requests in HTTP history** (`http.record_history`) on, every
request the scan sends and gets an answer for (in scope, admitted by the
engagement rules) is written to the vault's history with source `scan`,
in batches while the scan runs, up to 5,000 per scan; the scan's summary
says how many (`recorded_requests`) and the log warns when the limit cut
the rest. Blocked and refused requests stay in the scan log only. In
history, `source:scan` shows them apart from browser traffic
(`source:browser`), workstation requests (`source:repeater`), saved
attack results (`source:intruder`) and imports. Off by default, since a
scan can send many requests.

## Compare, re-run and diagnostics

A scan keeps every issue its engines report, whether it is new or
already known (`result_summary.observed`, at most 2,000). When it has
finished:

- **Compare** sets it against the previous finished scan of the same
  target. It lists the issues new in this scan, those still present, and
  those no longer observed (fixed, or out of the scan's reach this time;
  retest before closing a finding). Each opens its finding when there is
  one. Scans from before this was kept compare by the findings they
  created (`GET /scans/{id}/compare?other_id=`).
- **Re-run** queues the same scan again with the same start URL and
  settings. Scope, the engagement rules and the emergency stop are
  checked again at that moment, so a re-run of a target that left scope
  is refused (`POST /scans/{id}/rerun`; the row menu has it too).
  **Run again…** opens the new-scan dialog with the same target and
  engines, so you can change the settings.
- **Diagnostics** downloads one JSON document with the configuration,
  timings, summary (blocked hosts, TLS failures, counts), the observed
  issues and the stored log, for a bug report or an audit
  (`GET /scans/{id}/diagnostics`).

## Schedules

**Repeat** on a finished scan schedules the same target, start URL and
settings every 6, 12 or 24 hours, every 3 days or every week. Schedules
are listed under the scan history. Every minute, Phantom starts the ones
that are due. Each run is created exactly like a new scan, so scope, the
engagement rules and the emergency stop are checked when the run starts.
A run is never authorised just because the schedule was.

- A refused run (for example, the target left scope) is recorded with
  the reason and tried again at the next interval.
- A run is skipped while the schedule's previous scan is still queued or
  running.
- Right click a schedule to run it now, pause or resume it, or delete it.
  Its scans stay when it is deleted.
- Setting up repeated testing is the user's decision: agents and
  requests with agent headers are refused (`GET|POST
  /vaults/{id}/scan-schedules`, `PATCH|DELETE
  /scan-schedules/{schedule_id}`, `POST /scan-schedules/{schedule_id}/run`).

## Retention

Finished scans are kept forever unless you choose otherwise. At the foot
of the scan history, **Kept forever** opens the choices: 30 days, 90
days or one year after a scan ended. The newest three scans of each
target always stay, so Compare has something to compare with. Queued,
running and paused scans are never removed. A removed scan's findings
stay and are detached from it, as when you delete a scan yourself. The
policy is applied when you change it and every six hours. Changing it
is for you only (`GET|PUT /scan-retention`).

## Engines

- **Crawler.** Same-origin discovery of links, parameters and forms.
  It also reads same-origin scripts for the paths they name, so a
  single-page application's routes and API calls are found even when the
  page has no links. An OpenAPI or Swagger JSON document (linked, named
  in a script, or at `/openapi.json`, `/swagger.json` or `/v3/api-docs`
  while `crawl.api_metadata` is on) adds each GET operation's query
  parameters. Templated paths, other hosts and static assets are not
  followed, and only GET requests are sent: other methods in an API
  description are never called. To crawl behind a sign-in, give the scan
  the session in `http.headers` (for example a `Cookie`). Discovered
  parameters become injection points: payload-driven signatures are also
  sent against the target's own inputs.
- **Signature engine.** Runs YAML signatures: requests, matchers,
  extractors, multi-step chains and payload attacks. Each match becomes a
  [finding](./findings.md) with its evidence. Writing signatures is
  covered in [Signature authoring](../reference/signatures/index.md).

New engines plug into a registry and declare what they consume and
produce.

## Lifecycle

Queued scans wait in one line per vault and the scan workers
(`SCAN_CONCURRENCY`, 2 by default) serve the lines in turn, so a vault
with many queued scans never holds every worker while another vault
waits; within a vault, scans run in the order they were queued. The
waiting count per vault is in Settings › Diagnostics and in the
`phantom_scan_waiting` metric.

A scan is `queued`, then `running` (and `paused` while you pause it), and
ends `completed`, `failed` or `cancelled`. Only the scan runner moves a scan between states, so the
stored status always matches what is happening. While a scan runs, the
interface shows its stages, progress and activity log from the
`scan.updated`, `scan.progress` and `scan.log` events. A scan can be
cancelled at any time. When the backend restarts, queued scans are queued
again and a scan that was running is failed with the reason. Deleting a scan keeps its findings.

**Pause** on a running scan stops it before its next request: a request
already sent finishes, nothing new leaves, and the scan keeps its worker
and its place. **Resume** carries on from there; **Cancel** ends it. A
pause lasts until Phantom stops: a scan still paused then is failed as
interrupted, like a running one. Scans that run on an execution
environment's worker cannot be paused.

Right click a scan in the history (or on a target's Scans tab, or
Shift+F10 on it) to open it, pause or resume it, cancel it while it is active, run it again with the
same engines, show its target, copy its link (`[[scan:id]]`), attach it to
the agent conversation, or delete it once finished (Del), confirmed in the
row.

## Signature library

The **Signatures** page lists the built-in signatures shipped in
`backend/templates/` and your own. Built-ins are read-only (duplicate one to
change it); your own can be written in the editor, validated by the
backend parser and enabled or disabled. Only the backend parses and validates signatures, so the
interface, REST and agents always agree on what is valid.

Right-click a signature in the catalogue (or Shift+F10) to open it,
duplicate it as a custom copy, enable or disable it, copy its id, or (for
your own) delete it after a confirmation in the row.

## REST and MCP

| Operation | REST | MCP tool |
|---|---|---|
| Engines | `GET /api/v1/engines` | |
| List, start | `GET`, `POST /api/v1/vaults/{vault_id}/scans` | `scan_list`, `scan_start` |
| Read | `GET /api/v1/vaults/{vault_id}/scans/{scan_id}` | `scan_get`, `scan_logs` |
| Pause, resume | `POST .../scans/{scan_id}/pause`, `.../resume` | `scan_pause`, `scan_resume` |
| Cancel | `POST .../scans/{scan_id}/cancel` | `scan_cancel` |
| Delete | `DELETE .../scans/{scan_id}` | `scan_delete` |

Starting, pausing, resuming and cancelling scans needs the `testing` grant; reading them
needs `vault_meta` ([Agent permissions](../agents/permissions.md)). Headers
and logs returned to agents are redacted.
