# Requests

The `requests` list describes what a signature sends. Each entry is a
request block: one method with one or more paths, or one or more raw HTTP
requests, together with the matchers and extractors that judge its
responses. Blocks run in order, and a signature matches when any block
produces a match.

## Request blocks

```yaml
requests:
  - method: POST
    path:
      - "/api/login"
      - "/login"

    headers:
      Content-Type: application/json
      X-Request-ID: "{{rand_text_alphanumeric(16)}}"

    body: '{"username": "admin", "password": "admin"}'

    matchers:
      - type: status
        status:
          - 200
```

| Field | Default | Meaning |
|---|---|---|
| `method` | `GET` | `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD` or `OPTIONS` |
| `path` | | One path or a list. Each path is sent as its own request. |
| `headers` | `{}` | Header names and values; values may contain placeholders. |
| `body` | | Request body as text; may contain placeholders. |
| `raw` | | Raw HTTP requests, used instead of `method`, `path`, `headers` and `body`. |
| `matchers`, `matchers-condition` | `or` | Matchers for this block, see [Matchers](./matchers.md). |
| `extractors` | | Extractors for this block, see [Extractors](./extractors.md). |
| `payloads`, `attack` | `batteringram` | Payload lists, see [Payload attacks](./attacks.md). |
| `stop-at-first-match` | `false` | Stop this block, and the signature, at its first match. |
| `id` | `req_<index>` | Optional name for the block. |

A block needs a `path` or a `raw` entry; validation rejects a block with
neither. A signature without any `requests` sends a single `GET /`.

## How URLs are built

A path is appended to the scan target's URL. The target's query string
and fragment are dropped first, but its path is kept, so a target of
`https://shop.example/app` with the path `/login` requests
`https://shop.example/app/login`. A path that is already an absolute
`http://` or `https://` URL, for example one built from the `RootURL`
placeholder, is used as it is.

```yaml
path:
  - "/.env"
  - "{{RootURL}}/.git/config"
```

Every request passes the vault's scope check, so a path cannot reach a
host the vault does not allow.

## Raw requests

A raw request is written as it would appear on the wire: the request
line, header lines, an empty line and the body. We take the method and
path from the request line, the headers up to the first empty line, and
everything after it as the body. The destination is always the scan
target; a `Host` header is sent as a header but does not change where the
request goes.

```yaml
requests:
  - raw:
      - |
        POST /api/v1/search HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/json

        {"query": "phantom"}

    matchers:
      - type: word
        words:
          - "results"
```

Placeholders in raw requests are filled in before the request is parsed.
`raw` accepts one request or a list; each is sent in turn. Payload lists
are not applied to raw requests: when a block has `payloads`, its `path`
entries are used and `raw` is ignored.

## Matchers and extractors per block

When a block has its own `matchers`, only they decide whether its
responses match. A block without matchers falls back to the signature's
top-level `matchers` and `matchers-condition`. Extractors work the same
way: block-level extractors replace the top-level ones for that block.
Extractors run only on responses that matched.

Each matching response becomes one result. A signature with several
paths or payloads can therefore produce several results, and all of them
are attached to the single finding as evidence (up to 20).

## Multi-step chains

Blocks run one after another and share the signature's variables, so a
value extracted from one response can be used in a later request. Mark
the extractor `internal: true` and give it a `name`; the first value it
finds becomes a variable with that name.

```yaml
requests:
  - method: POST
    path:
      - "/api/login"
    headers:
      Content-Type: application/json
    body: '{"username": "{{username}}", "password": "{{password}}"}'

    matchers:
      - type: status
        status:
          - 200

    extractors:
      - type: json
        name: token
        internal: true
        json:
          - "access_token"

  - method: GET
    path:
      - "/api/admin/users"
    headers:
      Authorization: "Bearer {{token}}"

    matchers-condition: and
    matchers:
      - type: status
        status:
          - 200
      - type: word
        words:
          - "\"users\""
```

Two rules follow from how the engine works today:

- Extraction happens only when the step matched, so a step that provides
  a value needs a matcher that is true when the value is there.
- A step that matches counts as a match of the signature. In the example
  above a successful login alone produces a finding. There is no way yet
  to mark a step as a silent precondition, so keep the first step's
  matchers as specific as the finding itself, or keep chains for cases
  where every step is part of the evidence.

If a later step uses a variable that was never set, the placeholder is
sent as literal text.

## Stopping early

`stop-at-first-match` at the top level stops the signature after the
first request block that produced a match; later blocks are not sent.

On a block, it stops that block's remaining paths after the first match
and also ends the signature after that block. The per-path stop applies
to plain path lists; for payload attacks all requests of the block are
sent concurrently, and only the move to the next block is skipped.

```yaml
stop-at-first-match: true

requests:
  - method: GET
    path:
      - "/admin"
      - "/administrator"
      - "/wp-admin"
    stop-at-first-match: true
```

## Injection paths

When the scan's crawler finds pages with query parameters, it publishes
them as injection points such as `/search?q=` with a payload placeholder
in the value. Before a signature runs, those paths are appended to every
block that has `payloads` and at least one path of the form
`?name=` followed by a placeholder. Fuzzing signatures written this way
test the parameters the target really has, in addition to the generic
ones they list.

```yaml
requests:
  - method: GET
    path:
      - "/?id={{payload}}"
      - "/?search={{payload}}"
    payloads:
      payload:
        - "'"
        - "\""
```

The appended paths use the placeholder name `payload`, so name the
payload list `payload` in signatures meant to fuzz discovered parameters.

## Redirects

`redirects: true` (or `follow-redirects`) makes this block follow
redirects, `false` stops it, and leaving it out keeps the scan's setting.
`max-redirects` limits the hops (at most 5). Every hop is checked against
the vault's scope, like any other request; a hop out of scope ends the
chain with the redirect response.

## Fields with limited or no support

| Field | What happens |
|---|---|
| `req-condition` | Accepted. It does not wait for an earlier block to match; it only skips the block when it is the first one. |
| `cookie-reuse`, `threads`, `self-contained` | Refused when the signature is saved: concurrency is the scan's `http.concurrency` setting, and every request goes to the scanned target. |

Any other key the engine does not know is refused too, with where it is
(see [Supported fields](./index.md#supported-fields)).
