# Secure development

**Last updated:** 2026-11-27T14:16:11-03:00 (UTC-3)

[Security and trust](/docs/security/trust/) · Quality · ADR 0169

This is m7gtw's secure development policy. It describes what happens on every change, and each step is verifiable: the release gate fails if any of them does not pass.

## The cycle of each change

1. **Recorded decision:** a change to a trust boundary, persistence, protocol or scale gets an ADR in docs/adr, with the comparison between the reference tools and the reason for the choice.
2. **Tests:** unit tests, real PostgreSQL, Redis and Memcached, and Playwright in the browser, under the console's real CSP.
3. **Adversarial counter-test:** invalid input, missing permission, a service down, replay and reactivation.
4. **Mutation testing** on security and billing changes. A surviving mutant becomes a test case.
5. **Real validation:** the feature runs in the gateway with the real external piece (IdP, vault, bucket, provider), on ephemeral infrastructure destroyed afterwards.
6. **Release gate** (`scripts/quality-gate.sh release`): all tests, plus the race detector and `go vet`, OpenAPI validation, compatibility with the official SDKs, the documentation site and the security scan below.
7. **Documentation and CHANGELOG** in the same commit.

## Security scanning

`scripts/security-scan.sh` runs in the release gate. Any finding fails the gate.

| Tool | What it looks for |
|---|---|
| `govulncheck` | Known vulnerabilities in Go dependencies that the code actually reaches, for the shipped Linux build and again for the Windows and macOS binaries (`windows/amd64`, `darwin/arm64`, `darwin/amd64`, T184): build-tagged files, the standard library and dependency code differ there |
| `gosec` | Go static analysis, medium severity or higher: command injection, file paths, SSRF, cookies, integer conversions and more |
| `golangci-lint` (gosec only) | The same gosec rules over every package: gosec alone type-checks a package from its absolute file paths, and `go/packages` splits a list longer than 16,383 characters into partial packages, so the late files of the large packages were never analysed (T048). golangci-lint loads by package |
| `gosec` and `golangci-lint` for Windows and macOS | The same rules with `GOOS`/`GOARCH` of each shipped Windows and macOS binary, over the packages that have platform-specific files (a `//go:build` line or a `_windows.go`-style name: today `internal/securefile`, `internal/netlisten`, `internal/neterr`, the extension SDK) and `cmd/gateway`, chosen by `security_replay.platform_packages` and kept only where they have files to build (T184). The Linux analysis never sees `*_windows.go`; its first run found three integer conversions in the Windows file reader, all bounded buffers (annotated in place) |
| `deadcode` | Go functions that no binary under `cmd/` or `scripts/` reaches; a helper only tests call belongs in a `_test.go` file. The allowlist in the script is empty |
| `staticcheck` (U1000, without tests) | Unused Go constants, variables, types and fields, which `deadcode` does not see |
| `npm audit` | Vulnerabilities in the dependencies of the console and the documentation site |
| `gitleaks` | Secrets in this project's git history and in changes not yet committed |
| `trivy` | High and critical vulnerabilities in all lockfiles and, at release, in the Docker image; misconfiguration in the Dockerfile, the Kubernetes manifests and the Helm chart, rendered with its default values and again with every optional template on (below) |
| Compose rules (`scripts/check-compose.py`) | Trivy has no Compose checks, so the project's own rules (`internal/composecheck`, T184) over every Compose file (`compose.yaml`, `docker-compose.yml`, `docker-compose-<name>.yml`, `<name>.compose.yaml` and their override and `.json` forms) and the one the offline bundle writes, rendered by the preparer's own builder from the inputs it takes (local tags, never a digest reference): `privileged`, host network/PID/IPC/UTS/user/cgroup namespaces, a container engine socket or a host directory that holds one (`/`, `/var`, `/run`, `/var/run`, `/run/containerd`, `/run/user/<uid>`, `~/.docker`...), even mounted read-only, a writable host path (a named volume whose `driver_opts` bind a host directory, `o: bind`, counts as one), a missing `read_only: true`, `cap_add`, `cap_drop` without `ALL`, no `no-new-privileges:true`, seccomp/AppArmor/SELinux turned off (`label=disable`) or an unconfined SELinux type (`label=type:spc_t`, `unconfined_t`), host devices, a published port not on loopback, a secret-named variable with a literal value or default, a URL with a literal password in any variable (`postgres://user:password@host`), an image without `@sha256`. Values are read as Compose reads them with no environment: in a path, port, image or environment value `${NAME:-default}` is its default, while `${NAME:?message}`, `${NAME}` and `${NAME:+value}` (set only when the variable is) are operator-supplied and never taken as safe; the settings that decide privilege (`privileged`, the namespace modes, `read_only`, `cap_add`, `cap_drop`, `security_opt`, `devices`, `device_cgroup_rules`) take no interpolation at all, and a host path the operator supplies may be one holding the engine socket. The project's own Compose files must be found: the generated document alone does not pass. Every gate mode runs it (under a second once built) |
| `syft` | CycloneDX SBOM (below) |
| `check-licenses.py` | Component licenses from the SBOM ([third parties and licenses](/docs/security/third-party/)) |

Tool versions are pinned in `scripts/security-inputs.lock.json` and installed by `scripts/install-security-tools.sh`, outside the repository; see [pinned gate inputs](#pinned-gate-inputs). The accepted publication policy requires refreshing advisory inputs before **every new publication**, then pinning an immutable snapshot for an offline verdict; see [offline verdict from the captured bundle](#offline-verdict-from-the-captured-bundle). Historical replay does not authorize a new publication.

**False positives** are not ignored wholesale:
- in `gosec`, each one gets a `#nosec` annotation in the code itself, with the rule and the verified reason;
- in `deadcode`, an accepted finding goes into the allowlist of `scripts/security-scan.sh` with its reason, and in `staticcheck`, into a `//lint:ignore U1000` annotation in place; the only ones are the Windows listener helpers of `internal/netlisten/sockaddr.go`, which only `listen_windows.go` calls and which carry no build tag so their tests run on every system;
- in `gitleaks`, each synthetic or public value goes into `.gitleaks.toml` as an exact pattern, never a whole test directory.
- in the Compose rules, each accepted finding goes into `.compose-exceptions.yaml`: the rule, the exact `path#service` with the number of findings read there, and a statement; one more finding there, another service, or an entry that accepts more than exist fails. Tooling Compose files that never ship (the owned test runner's services) are listed under `excluded`, only below `deploy/validation/` or `docs/benchmarks/`, with a reason, and an exclusion of a missing file fails. Today it accepts two kinds of finding: the image by tag, for the gateway (the project's own build, in Compose and its external profile) and for both images of the offline bundle, which approves them by content ID in its manifest because a loaded archive cannot be referenced by registry digest offline; and the two read-only host paths of the external profile, the operator's reviewed gateway YAML and certificate directory, which the check cannot see;
- in Semgrep CE (the push workflow, not the release gate: continuous integration), each accepted finding's rule and exact file go into `.semgrep-exceptions.yaml` with a statement of why; a stale entry fails too.

**Counter-test:** the scan was exercised with a planted secret, a command built from request input and a dependency downgraded to a vulnerable version. It failed in all three cases, each in the right scanner.

## Pinned gate inputs

The verdict of the security scan depends on the scanners, their rule sets and policies, the flags each scanner runs with, the configuration they load implicitly, and the advisory data they read. `scripts/security-inputs.lock.json` pins the scanners, rule sets, policies and advisory sources, and `scripts/check-security-inputs.py` fails when one is missing or drifts. The check is offline and uses only the Python standard library; every gate mode runs it, together with its counterexamples in `scripts/test_check_security_inputs.py`.

| Input | Pinned as | The check fails when |
|---|---|---|
| Go scanners (`govulncheck`, `gosec`, `golangci-lint` as `golangci`, `deadcode`, `staticcheck`, `gitleaks`) | Exact module version, package and Go module checksum (`h1:`, as published by the Go checksum database) | A version is not exact `vMAJOR.MINOR.PATCH`, the checksum is missing, the installer's version line differs, the installer does not check the checksum, or the capture's module map disagrees |
| Release scanners (`trivy`, `syft`) | Exact version, release URL and the archive SHA-256 for each supported platform (macOS and Linux, arm64 and amd64) | A platform digest is missing or malformed, or the installer trusts a checksum file downloaded next to the archive |
| Scanner list | The lock's tool set | `scripts/security-scan.sh` runs a scanner the lock does not pin, or the reverse |
| Rule sets and policies | SHA-256 of `.gitleaks.toml` (secret-scan exceptions), `.trivyignore.yaml` (accepted misconfigurations), `.compose-exceptions.yaml` with everything else the Compose verdict depends on (`internal/composecheck/check.go`, `exceptions.go`, `cmd/composecheck/main.go`, `internal/lazyregexp/lazyregexp.go`, `scripts/check-compose.py` and `scripts/offline_bundle.py`, which builds the offline Compose document it checks) and the Helm scan profiles (`deploy/helm/security-scan/*.yaml`), `scripts/check-licenses.py` (license policy), `scripts/security-scan.sh` (scanner flags, severities, dead-code allowlist), `scripts/security_secrets.py` (secret-scan coverage) and the `.npmrc` of the console and the site (npm audit settings) | A file changed without re-pinning, a required policy is not listed, or the advisory capture does not bind it (the `.npmrc` files are pinned by the lock alone: the capture never reads project npm configuration) |
| Implicit scanner configuration | Must be one of the pinned policies | A `.trivyignore`, `trivy.yaml`/`trivy.yml` or `.npmrc` exists at the project root, or a `staticcheck.conf` in any package, without being pinned: each would be loaded silently and could suppress findings |
| Advisory sources | The Go vulnerability database, Trivy database and checks, and the npm registry, each with `pin: publication_manifest` | A source differs from the one `scripts/security_capture.py` fetches |

Advisory **data** is never stored in the lock. Under the owner's policy it is refreshed before every new publication and pinned by the SHA-256 of that publication's capture manifest (below); the lock pins where it comes from, and the capture binds the lock and the checker among its inputs.

The installer reads the lock. Before building a Go scanner it asks `go mod download -json` for the module checksum and stops on any difference. It overrides the ambient Go settings for the install: `GOENV=off` (the user's `go env -w` file is ignored), `GONOSUMDB`, `GOINSECURE`, `GOPRIVATE`, `GONOPROXY` and `GOFLAGS` cleared, `GOSUMDB=sum.golang.org`, `GOPROXY=https://proxy.golang.org`, `GOTOOLCHAIN=local`, and a fresh private module cache, so neither an exemption nor a modified cached source can pass for the pinned module. A release archive is installed only when its SHA-256 equals the lock's digest for the platform. A mismatch exits non-zero before the tool is placed. After installing, it writes `security-inputs.stamp.json` next to the tools with the tool pins and the SHA-256 of each binary it verified.

The release scan starts with `python3 scripts/check-security-inputs.py --tools <dir>`, which proves the installed scanners are the ones the installer verified for the current pins: each binary's SHA-256 must equal the stamp, a stamp written for other pins is refused, each Go binary must embed the pinned module path, version and checksum without replaced modules or link-time flags (`go version -m`), and `trivy` and `syft` must report the pinned version. A stale, replaced or missing binary stops the scan before any verdict; tools installed before this check have no stamp, so run the installer again. The scan then clears `TRIVY_*` and `npm_config_*` variables and `GOFLAGS`, and sets `GOENV=off`, so ambient settings cannot change the verdict. Full and release gates require the installed tools and `go` for the identity counterexamples; fast reports an explicit skip without them.

The stamp lives next to the tools: anyone who can replace a binary there can rewrite it too. It detects stale and accidentally replaced tools, not a local attacker with write access to the tools directory.

**Changing an input** is a reviewed commit:

- A scanner upgrade changes the version line in `scripts/install-security-tools.sh` and the lock entry together: the new module checksum from `https://sum.golang.org/lookup/<module>@<version>`, or the new archive digests from the release's published checksums, compared before they are written.
- A rule or policy change (a new secret-scan exception, an accepted misconfiguration, a scanner flag) is reviewed, then re-pinned with `python3 scripts/check-security-inputs.py --write-policy-digests`, which rewrites only the policy digests.

The host Go toolchain, Node and npm versions also influence results; the capture records them and the offline replay refuses a host whose versions differ (below), but the lock does not pin them.

## Capture current security intelligence

Every new publication requires a new explicit refresh. Install the pinned tools with `scripts/install-security-tools.sh`, then run from the project directory:

```sh
python3 scripts/refresh-security-inputs.py \
  --publication release-candidate-001 \
  --output test-results/security-inputs
```

Use a unique lowercase publication identifier (letters, digits, dots, underscores or hyphens; at most 80 characters). An existing destination, including an empty directory or symlink, is refused. The output directory is created owner-only; existing output directories must already have owner-only permissions. Paths must use canonical nonsymlink components. Staging uses the OS private temporary directory on the same filesystem as the output; a cross-filesystem commit is refused, with no copying fallback.

`--root` defaults to this project. `--tools` defaults to `~/.cache/ai-gateway-tooling/bin` or `SECURITY_TOOLS`. The command records exact scanner versions and executable SHA-256 identities, host tool identities, platform, manifest/lock and security-policy digests, exact settings and capture timestamps. It does not read provider credentials or load personal Git/npm/Docker configuration. Source files and tools are rechecked before committing the capture.

| Source | Captured and validated |
|---|---|
| Go vulnerability database | Fresh public bulk ZIP, all advisory files and three indexes; full ID, timestamp and affected-module reference multiplicities must agree |
| Trivy vulnerability database | New private cache, schema/framing checks and actual pinned reader; global/old caches are not substituted |
| Trivy checks | Public OCI manifest and compressed layer, pinned by digest before Trivy loads them; complete paths and SHA-256 values must match every cached content file, with no missing or extra member |
| npm console and docs | Exact private manifest/lock copies, neutral project/user/global configs, explicit public registry and all dependency classes; report shape, lock references, full overlapping inventory counters and command exits must agree |

npm capture uses no transport retry and a 120-second request timeout. Links, root workspace installations and dependencies without the supported version/location profile are rejected; published workspace metadata on an ordinary dependency does not make it a workspace installation. Advisory findings are preserved, including exit 1, rather than discarded as transport errors. A clean npm inventory alone cannot prove registry advisory completeness: the capture also binds the exact trusted tool, command/settings and full manifest/lock inputs. The supported report profile is npm audit report version 2, validated with npm 11.19.0.

Source bodies remain only in the private working directory and are removed before commit. Ignored project npm configuration is neither read nor copied. The accepted bundle retains source/policy hashes, public intelligence and reports.

The resulting `<output>/<publication>/manifest.json` binds every file below `data/`. SHA-256 proves integrity, not a publisher signature or release authorization. The command prints the manifest hash only after successful capture. Private payloads are limited to 8 GiB and 100,000 entries; exceeding a limit fails rather than truncating coverage. Reserve space for the database and temporary download/cache data; the actual validation database was about 1.7 GB before the remaining artifacts. Keep the printed hash in trusted release evidence, outside the mutable bundle.

**Atomic acceptance:** the complete private directory is hashed, made durable and verified before one native exclusive rename makes it visible. There is no check-then-overwrite fallback. macOS uses `renameatx_np(RENAME_EXCL)` and Linux uses `renameat2(RENAME_NOREPLACE)`; unsupported hosts/filesystems fail closed. Native behavior was exercised on macOS arm64 and Linux arm64; the full public-source capture was exercised on macOS arm64. This does not certify a full Linux capture or change the gateway's runtime OS support.

Failure or cancellation before the rename leaves no new accepted bundle and preserves earlier bundles. After the rename, a durability, output-identity or cleanup failure reports **completion uncertain** and exits unsuccessfully; the complete committed bundle stays immutable and is never rolled back or replaced. Preserve it for investigation, verify the requested output identity and recorded manifest hash, and resolve durability/cleanup before relying on any artifact. That status does not authorize shipping. Snapshot verification checks bytes and structure; it is not an offline vulnerability verdict.

This command is **capture only**; the verdict is the offline replay below.

## Offline verdict from the captured bundle

A ship verdict comes only from replaying one captured bundle offline (T053.003–T053.006). A new publication does both in one step, and the release gate runs it:

```sh
scripts/security-scan.sh --publication release-candidate-001
# optional image profile, from an explicit local archive (no registry):
docker save -o gateway.tar ai-gateway:candidate
scripts/security-scan.sh --publication release-candidate-001 \
  --image-archive gateway.tar --image-sha256 "$(shasum -a 256 gateway.tar | cut -c1-64)"
```

This captures the bundle into `test-results/security-inputs/<publication>` (network), then runs `scripts/replay-security-inputs.py` against exactly that bundle. Commit first: both steps require a clean tree. `scripts/security-scan.sh --replay <bundle dir>` replays an existing bundle on the commit it was captured from: it reproduces that bundle's verdict and never authorizes a new publication. Only `--image-archive` and `--image-sha256` may follow either form. The release gate names the publication from `SECURITY_PUBLICATION`, or `release-<revision>-<UTC time>`. Without arguments, `security-scan.sh` keeps the live scan as a developer intelligence check, never a ship verdict.

Before any scanner runs, the replay refuses to give a verdict unless:

- the pinned-input check passes (`scripts/check-security-inputs.py --tools`: tool stamp, implicit scanner configuration);
- the bundle's manifest verifies every byte below `data/`;
- the project source is the one the capture recorded: the same commit, the same SHA-256 of the project's index entries, and a clean tree both at capture and now: no modified tracked file, no untracked file, no skip-worktree or assume-unchanged entry and no ignored Go, YAML, Terraform, Dockerfile or lock file (all hidden from `git status` but read by the scanners). Two kinds of ignored output do not count, because they cannot change a verdict: the non-Go files under the directories every replayed Trivy and Syft run skips (`docs-site/dist/`, `test-results/`, where the bundles themselves live; a Go file there still counts, since the Go analyses walk `./...`) and the site build's copy `docs-site/public/openapi.yaml` while it is byte-identical to the tracked `api/openapi.yaml`. Before T048 the site build of the release gate made every release capture "unclean";
- every source input the capture recorded (Go and npm manifests and locks, rule sets, policies, the scan, capture and replay scripts, the lock) has the same SHA-256 now; the error names what changed;
- every scanner executable has the SHA-256 the capture recorded, and `go version`, `node --version`, `npm --version` and `helm version --short` print what the capture recorded (govulncheck reports standard-library findings for the `go` it runs with; helm renders the chart's opt-in profiles, and CI installs the pinned one from `scripts/ci-tools.lock.json`);
- the bundle's advisory sources equal the lock's;
- the host proves the network denial: a grandchild process connects to a local listener without the wrapper, and with it the wrapper runs a program (a nonce is echoed) while the grandchild's connection is refused (its own exit status 7). macOS uses a `sandbox-exec` profile denying all network; Linux a new network namespace (`unshare --net`). Denial the replay did not observe is no verdict. Limits: Linux namespaces leave filesystem Unix sockets (for example a Docker socket) reachable, and on macOS name resolution through the system resolver service still works; neither carries scanner data.

Go analyses run with explicit settings only: `GOENV=off`, `GOFLAGS=-mod=readonly`, `GOPROXY=off`, `GOSUMDB=off`, no checksum exemptions, `GOTOOLCHAIN=local`, `GOWORK=off`, a private build cache, and `go mod verify` against `go.sum` first. They analyse the shipped build configuration, `GOOS=linux CGO_ENABLED=0` with the host's architecture, not the host's (build-tagged files differ), and then each other shipped target (`GO_PLATFORMS`: `windows/amd64`, `darwin/arm64`, `darwin/amd64`). govulncheck included: v1.1.4 panicked building the Linux standard library of Go 1.27, and the pinned v1.9.0 does not. Trivy and Syft run with an empty `--config` file, so no `trivy.yaml` or `.syft.yaml` changes their settings. The module cache is a fresh private download through the checksum database made before the denied step (`--modcache` reuses an existing one, which `go mod verify` still checks). Ambient `TRIVY_*`, `npm_config_*` and `GOFLAGS` never reach a scanner.

| Check | Offline input | Fails on |
|---|---|---|
| govulncheck | `data/go-db` through `file://`; its reported database and modification time must be the bundle's | A called vulnerable symbol |
| gosec | Source, private caches | Medium severity and confidence and up (exit status must agree). Files it could not type-check are listed but decided by the next row (the replay runs it without `-quiet`, which writes no report for a clean tree) |
| gosec-packages | Source, private caches; golangci-lint 2.15.0 with only gosec enabled (it embeds gosec 2.29.0, so these are that release's rules; the standalone 2.30.0 adds its newer ones where it can type-check), no exclusions, generated files included, unlimited issues | Any gosec finding; any other issue (a type-check or load error means a package was not analysed); any `//nolint` directive in shipped Go code, since golangci-lint honours it and a suppression must be a `#nosec` with its reason: fail closed |
| deadcode | Source; inverse control `-whylive` must find `gateway.New` | Any unreachable function |
| staticcheck | Source | U1000 without tests; exit status must agree with the findings |
| gitleaks | History, exact index, deliverable working tree | Any finding |
| npm | The recorded full `npm audit` reports, re-validated against the current locks, the recorded settings and counts | Low or higher. `npm audit --offline` is never used as evidence |
| trivy fs | Bundle database through a private cache (copy-on-write clones or copies, never links); `go.mod` and both npm locks must be reported | HIGH/CRITICAL |
| trivy config | Bundle checks; Trivy's log must show the checks loaded from disk (the embedded fallback is refused); every tracked Dockerfile and static Kubernetes manifest, the Helm chart and each Terraform directory must be reported (a file Trivy cannot parse is otherwise silently absent). The scope is what ships for deployment and has Trivy checks: the Dockerfile, the Kubernetes manifests and the Helm chart rendered with its default values (trivy-helm below renders it with every optional template, the compose row covers Compose, which Trivy has no checks for, and the image is scanned for vulnerabilities only when the publication is given its archive). The Terraform, manifests and containers of the disposable validations and of the benchmark rig (`deploy/validation/cloudsql`, `deploy/validation/windows-ec2`, `deploy/validation/gke-vault`, `deploy/validation/sagemaker-endpoint`, `deploy/validation/gke-multiregion`, `docs/benchmarks/kit/terraform`) are tooling that never ships and is skipped, by name and with a reason, in `CONFIG_TOOLING_EXCLUDED` of `scripts/security_replay.py`; the replay refuses an entry outside `deploy/validation/` and `docs/benchmarks/` or one that is or holds a product path (owner decision of 2026-11-19) | MEDIUM+ failures after `.trivyignore.yaml` |
| trivy-helm | The chart rendered by `helm template` with each profile of `deploy/helm/security-scan` (T184): `bundled.yaml` turns on the bundled database and analytics store, the Collector, Ingress with TLS, NetworkPolicy with egress, HPA, PodDisruptionBudget, topology spread, ServiceMonitor with both PrometheusRules, Service and metrics annotations, a created ServiceAccount, the trust Secret and extra env/volumes; `external.yaml` the external database, the migration Job and KEDA, which the chart refuses beside the first. helm renders it because Trivy's own Helm renderer drops hook manifests (the migration Job); the output keeps the chart's paths, so `.trivyignore.yaml` applies unchanged. Same bundle checks and loaded-from-disk proof as trivy config; every rendered file must be reported, and every template must be rendered by one profile (`verify-helm-chart.sh` checks the same in every mode, so a new optional template needs its switch there). The live `scripts/security-scan.sh` renders the same profiles, fails the same way when a template is never rendered, and skips `test-results/` (where it writes that output) in its root `trivy config .`, as the replay does | MEDIUM+ failures after `.trivyignore.yaml` |
| compose | `scripts/check-compose.py` (above), built for the host, offline | Any finding `.compose-exceptions.yaml` does not accept, a stale entry, or no Compose file found; a malformed file or exceptions entry is no verdict |
| govulncheck, gosec, gosec-packages `-<os>-<arch>` | The same inputs, with `GOOS`/`GOARCH` of `windows/amd64`, `darwin/arm64` and `darwin/amd64`; govulncheck over `./...`, gosec and golangci-lint over the platform packages and `cmd/gateway` | As their Linux rows |
| syft | Source | Empty or non-CycloneDX SBOM, no Go or no npm component, license policy. It does not compare coverage package by package with the locks |
| image | `--image-archive` with its SHA-256, read by `trivy image --input` and `syft docker-archive:`/`oci-archive:` | HIGH/CRITICAL; a different or changed archive is refused |

The checks run concurrently, at most four at a time; the Trivy checks run one at a time on a worker of their own (their runs share the cache directory), so waiting for each other never takes a slot from the other checks; the report keeps their order, every check runs to its end, and the first failure in that order is the one raised. On the reference host (12 cores) the replay took 89 s before T184 and takes about 141 s with the 12 new checks, against about 240 s for the same checks one after another. An unknown exit status, malformed scanner output or a changed bundle after the scanners ran is no verdict. The report `test-results/security/replay-<publication>-deny.json` records each check's verdict, details and a normalized evidence digest; `--network allow` produces the same report from the same bundle for comparison only. Exit status: `0` every check passed with the network denied, `1` a finding or no verdict, `2` usage, `4` a comparison run passed (never a ship verdict). Each publication keeps a bundle of about 2 GB under `test-results/security-inputs`; remove old ones you no longer need to replay.

Full/release gates run deterministic capture regressions, including actual npm/Arborist against a disposable loopback registry, a HIGH advisory fixture, neutral configuration/auth isolation, an endpoint failure, the real Trivy corrupt-database rejection, source/archive integrity, cancellation, native atomic commit and cleanup. These tests fetch no public advisory data. Fast reports an explicit skip when a real tool is absent; full/release require it. Actual public refresh validation runs separately from that hermetic gate.

## Secret scanner inputs

The release scan delegates to `python3 scripts/security_secrets.py`, using Gitleaks 8.28.0 from `scripts/install-security-tools.sh`. Full/release gates require that pinned scanner for real regression counterexamples; fast runs them when installed and otherwise reports an explicit skip. Install the tools before full validation. These checks are contributor tooling and add no provider connection, runtime flag or user-facing configuration.

The helper covers three distinct inputs:

- History reachable from the selected HEAD, restricted to this project within a monorepo. Full ancestry and separate merge-parent diffs include subsequently deleted content, merged-away branch changes and content introduced only in a merge; it does not traverse unrelated branches or sibling projects.
- Raw staged index blobs, so a secret staged for commit is checked even if its working copy has been overwritten or deleted. No checkout filters or external diff drivers run.
- Current tracked files, including tracked files now matching an ignore pattern, plus nonignored untracked files. Ignored untracked files and build artifacts are outside the deliverable boundary.

The helper pins and reads local HEAD history and copies index/working inputs into a private temporary directory, uses the reviewed `.gitleaks.toml` exceptions, and supplies an empty fingerprint-ignore file. Inherited `GITLEAKS_*`, alternate Git indexes, global Git configuration and ambient credential variables do not control the scan. The existing Gitleaks detection rules are preserved; inline `gitleaks:allow` suppression is disabled, so only reviewed TOML exceptions apply. Success requires all three scans to exit cleanly with empty findings and no unexpected diagnostics. A finding, missing/malformed verdict, tool failure, cancellation or snapshot cleanup failure cannot produce a clean result. Raw findings, paths, file contents and scanner stderr are suppressed; the public summary contains only coverage counts.

Symlinks, submodules, unresolved index stages, special files, colliding snapshot paths and unsafe paths fail closed. Complete local ancestry is required: shallow history and legacy grafts are rejected without fetching. The history scan ignores mutable graft/shallow rewrites and cached commit graphs; missing objects never trigger lazy remote fetching. Explicit diff options prevent local presentation settings or binary attributes from hiding historical text, and external diff/textconv/signature programs do not run. Snapshot safety limits are 100,000 files per input, 64 MiB per file and 512 MiB of file contents per input; exceeding a limit fails rather than truncating coverage. The helper rechecks HEAD, index, file inventory and working content after scanning and rejects changes. A passing result applies to that captured revision/content; it does not authorize later edits.

Regression tests generate synthetic credentials only inside disposable repositories. They exercise clean and detected committed/staged/unstaged/untracked content, deleted history, a staged secret with a clean or missing working file, ignored tracked files, unusual filenames, monorepo isolation, approved synthetic exceptions, hostile environment/ignore files, source/index mutation, merged/root/binary-attribute history, inline suppression, external textconv refusal, incomplete ancestry, invalid verdicts and cleanup. The tests never use a provider key or call a provider.

## Component inventory (SBOM)

On every scan, `syft` generates `test-results/security/sbom-source.cdx.json`, with the Go modules, the npm packages of the console and the site, and their versions. With an image (`scripts/security-scan.sh image <image>`), it also generates `sbom-image.cdx.json`. The SBOM is the software asset inventory: it tells you whether a new vulnerability affects a published version without having to rebuild it.

## Dependencies

- A reachable vulnerability in a dependency is fixed by upgrading the version, not annotated as an exception.
- The image pins the Go patch version (`golang:1.27.4-alpine`): the minor-version tag once pulled a vulnerable standard library from the local cache. `go.mod` names the same patch as its `toolchain`, so a native build with an older local Go switches to it (Go 1.27.4 fixes GO-2026-6859 in `net/http`).
- Every dependency is pinned to an exact version: npm packages without ranges (with `save-exact=true` in each `.npmrc`), Python locks with `==` and hashes, tools by exact release, and every third-party image by exact tag **and** `@sha256` digest, so a re-pushed tag cannot change a build. `scripts/check-pinned-deps.py` enforces this in the gate. An upgrade is a deliberate commit that changes the version and the digest together.
- The image base is distroless, with no shell or package manager, and runs as non-root.

## What the first scan found

The first run, on 2026-10-27, found and fixed:
- **4 reachable vulnerabilities** in `pgx` (SQL injection and memory flaws), in `go-jose` (a JWE panic) and in `golang.org/x/text`;
- **20 high and critical findings in the image**, among them the Go 1.25 standard library, which no longer receives fixes;
- **one critical finding in `astro`** for the documentation site, which was upgraded to version 7;
- **a panic in the realtime meter:** a WebSocket frame with the highest bit of the 64-bit length set, which RFC 6455 forbids, became a negative length. The session is now marked as invalid, and a test reproduces the case.
