# Attack surface in CI: SARIF, code scanning and failing builds

Spiderfootplus can run in a pipeline and gate a deploy on what it finds about
the surface you expose: a new admin panel, an expired certificate, an open
database port, a weak mail policy.

Only scan targets you own or are authorised to assess. The `passive` profile
sends nothing to the target's own servers; anything else contacts them.

## The pieces

- `--fail-on SEVERITY` on `spiderfootplus scan` exits with code **5** when a
  finding of that severity or worse turns up (`critical`, `high`, `medium`,
  `low`, `info`).
- `-o sarif` on `export` (or `--out file.sarif` on `scan`) writes the findings
  as SARIF 2.1.0. Each correlation rule becomes a SARIF rule, with its
  description and a link to its page on spiderfootplus.com. Severities map to
  SARIF levels and GitHub's `security-severity`, and each finding carries a
  stable fingerprint so code scanning can track it across runs.

```sh
spiderfootplus scan example.com -p passive --out findings.sarif --fail-on high
echo $?   # 0, or 5 when a high or critical finding turned up
```

## GitHub Actions

This repository is also a GitHub Action. It installs a release, scans, writes
SARIF and fails the job per `fail-on`:

```yaml
name: attack-surface
on:
  schedule: [{ cron: "0 6 * * *" }]
  workflow_dispatch:

permissions:
  contents: read
  security-events: write   # upload to code scanning

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - id: sfp
        uses: osintambition/spiderfootplus@v0.8.0
        with:
          target: example.com
          profile: passive
          fail-on: high
      - uses: github/codeql-action/upload-sarif@v3
        if: always()      # upload even when fail-on stopped the job
        with:
          sarif_file: ${{ steps.sfp.outputs.sarif-file }}
          category: spiderfootplus
```

Inputs: `target` (required), `profile` (default `passive`), `fail-on`
(default: never), `sarif-file` (default `spiderfootplus.sarif`), `args`
(extra `scan` arguments such as `--skip staging.example.com`), and `version`
(a release tag; default latest). Outputs: `sarif-file`, `findings` and
`grade`. The job summary shows the grade and the finding count. The action
runs on Linux and macOS runners.

In code scanning, a finding has no source file. Each result points at the
path `spiderfootplus/<target>`, and the affected host or URL is in the
message and the result's logical location.

## Other CI systems

Install with the release script, run a scan, and act on the exit code:

```sh
curl -fsSL https://github.com/osintambition/spiderfootplus/releases/latest/download/install.sh | sh
~/.local/bin/spiderfootplus scan example.com -p passive --out findings.sarif --fail-on high
```

GitLab, Azure DevOps and most security dashboards read SARIF too.

To compare runs rather than gate on absolute findings, use
`spiderfootplus watch --once`, which exits with code 3 when anything changed
(see [Scan profiles and watch](https://spiderfootplus.com/docs/guides/profiles-and-watch)).
