Charlie Roffe

Principal Architect & Engineering Director · Cloud & AI

Madrid, Spain · LinkedIn · GitHub

ADR-020: Dual-Engine Security Pipeline — SAST, SCA, Secrets & DAST

Context

The runtime abuse stack (ADR-019) protects the deployed service, but nothing examined the code and supply chain before deployment. Four defect classes had no automated detection:
1. Code-level vulnerability patterns (injection, SSRF, weak crypto) — the backend concatenates user input into prompts and parses uploaded certificates, none of it statically analyzed.
2. Known-vulnerable dependencies — the production npm tree (13 direct dependencies plus their transitive packages), the container base images and Terraform, with new CVEs published daily; a tree that was clean at merge time rots silently.
3. Committed secrets — the project is deliberately keyless (ADR-008/009), but one accidental paste into a tracked file would be public on GitHub.
4. Response-level weaknesses in the running site — header hardening, information disclosure — only observable against a live deployment.

Constraint: the PR feedback loop is the heartbeat (ADR-012), so slow or flaky scans must not gate merges.

Decision

Adopt a dual-engine pipeline in a dedicated security.yml workflow: a static engine gating every PR, and a dynamic engine probing the live staging deployment out-of-band.
* SAST — Semgrep (p/default ruleset): fails the build on ERROR-severity code patterns.
* SCA — Trivy (dependency CVEs + Dockerfile/Terraform misconfiguration, HIGH/CRITICAL, fixable only) and npm audit (production tree, high+, no exceptions), both also re-run weekly against main because new CVEs land daily.
* Secrets — Gitleaks over every commit in the PR, so a credential committed and later "removed" is still caught; a manual run scans the full history.
* DAST — an OWASP ZAP baseline scan against the staging deployment, weekly and on demand. Deliberately decoupled from the PR gate: a PR's code is not yet deployed when the PR runs, so gating on DAST would test the previous deployment — misleading and slow.
Every scan job runs with read-only permissions (contents: read, plus pull-requests: read for the static job); no deployment credentials are reachable (ADR-012 isolation).

Amended 2026-10-16: the workflow runs on PRs, weekly and on manual dispatch, not on push; Semgrep and Gitleaks skip the weekly run. The runtime image is distroless (gcr.io/distroless/nodejs26-debian13:nonroot, ADR-022).

Consequences

Benefits:
* Shift-left coverage: vulnerable patterns and dependencies are caught at PR time, before an image is built.
* Supply-chain decay detection: the weekly pass surfaces newly published CVEs in already-merged code within days.
* Commit-level secret detection across every commit in a PR.
* The "dual-engine security pipeline" described in the README is now real, public, and verifiable in the workflow run history.

Trade-offs:
* ~1–2 minutes of parallel wall-clock added per PR (runs concurrently with the existing CI matrix).
* Semgrep and ZAP will occasionally flag intentional patterns; suppressions must be reviewed and documented, not blanket-ignored.
* The DAST baseline is passive — it does not actively attack. Acceptable for this threat model; manual dispatch re-runs the same passive baseline.

Alternatives considered

1. Delete the README claim instead: Honest but weaker — the claim describes a control this architecture genuinely needs (a public API fronting paid model calls), and building it cost an afternoon.
2. GitHub Advanced Security / CodeQL only: Excellent SAST, but covers neither dependency CVEs, IaC misconfiguration, secrets history, nor DAST; the chosen stack covers all four with free, vendor-neutral tools.
3. Gating PRs on DAST: Rejected — it scans the previously deployed code, not the PR's, adding serial minutes for a misleading signal.
4. Snyk SaaS: Strong SCA, but adds a third-party account and quota dependency to a zero-budget project; Trivy + npm audit cover the same ground in-repo.

Architecture Decision Records