# Write a vulnerability template

The template scanner checks web hosts for exposed files, panels and
misconfigurations. A template is a YAML file in
`crates/spiderfootplus-templates/templates/`; it is embedded into the binary at build time, so
adding one is just dropping in a file.

```yaml
id: env-file-exposed
info:
  name: Exposed .env file
  severity: high              # critical | high | medium | low | info
  tags: [exposure, config]
http:
  - method: GET
    path: ["/.env", "/.env.local", "/.env.production"]
    stop-at-first-match: true
    matchers-condition: and   # all matchers must pass
    matchers:
      - type: status
        status: [200]
      - type: regex
        part: body            # body | header | status | all
        regex: ["(?m)^[A-Z0-9_]+=", "(APP_|DB_|AWS_|SECRET|API_KEY)"]
        condition: and        # all regex must match
```

## Matchers

| type | matches on |
| --- | --- |
| `status` | the HTTP status code (`status: [200, 403]`) |
| `word` | literal substrings (`words: [...]`, `condition: and/or`) |
| `regex` | regular expressions (`regex: [...]`) |

Each matcher takes `part` (`body` default, or `header`/`status`/`all`),
`case_insensitive: true`, and `negative: true` to invert it. The request's
`matchers-condition` (`and`/`or`) combines the matchers.

## Avoid false positives

Single-page apps return `200` with HTML for almost any path. Always pair a status
matcher with a **content signature** — a word or regex that proves the file is
really what you think, like `"[core]"` for a `.git/config` or
`"-----BEGIN .* PRIVATE KEY-----"` for a key. The bundled templates are good models.

## Severity

Severity maps to the finding's event type (`VULNERABILITY_CVE_*` /
`VULNERABILITY_GENERAL`) and feeds the vulnerability correlation rules.

## Test it

```sh
cargo test -p spiderfootplus-templates
spiderfootplus templates                 # confirm it loads with the right severity
spiderfootplus scan <a test host> -m template_scan
```

## Importing existing template sets

`spiderfootplus templates --dir <path>` imports templates from a directory in the common
public format; unsupported DSL features are skipped and reported.

The template format mirrors the widely-used public one (`id`, `info`, `http` with
`matchers` / `extractors`, `matchers-condition`, `part`, `negative`, …), so most
community templates drop in unchanged. To run your own directory alongside the
built-in set — without rebuilding — point a scan at it:

```sh
spiderfootplus scan <host> -m template_scan --set template_scan.templatedir=./my-templates
```

Everything there is loaded on top of the 30+ bundled checks, so you can grow the
scanner's coverage just by adding YAML files.
