Lesson 2 of 12 · 20m
Anatomy of a Security-Aware Pipeline
Five stages, five latency budgets, and the rule that decides where each control lives: fast and deterministic early, slow and probabilistic late.
A CI pipeline has five distinct stages, and a control dropped into the wrong one is either useless or hated. The wrong mental model is "add a security job at the end of the build" — as if security were a step. It's not a step; it's a set of controls distributed across the lifecycle, each spending a different latency budget. Map the stages before you install anything.
The five stages
- Pre-commit — seconds. Formatting, linting, secrets detection (
gitleaks protect --staged). Only controls that are fast and near-zero false positives earn a spot here; a hook that takes forty seconds or cries wolf trains developers to type--no-verify, and once that muscle memory exists every hook is dead. - Pull request — minutes. Incremental SAST on the diff (
semgrep ci, driven bySEMGREP_APP_TOKEN), dependency review on changed lockfiles (actions/dependency-review-action), unit-level security tests. This is where blocking is cheapest: the change is open and the author is right there. - Post-merge / scheduled — unbounded. Full-repo SAST, deep dependency scans, DAST against staging. The slow, thorough, occasionally noisy work lives here and reports to a triage queue — not to a red X on somebody's merge.
- Build / publish. Container image scanning, SBOM generation, artifact signing. These operate on the artifact you're about to ship, not the source — a distinction that matters when the question is "does this image contain CVE-2024-3094."
- Runtime. Rescanning deployed images as new CVEs drop. Code doesn't change after deploy, but the vulnerability database does: last Tuesday's clean image has three new CVEs today.
A realistic PR stage
on:
pull_request:
schedule:
- cron: '17 4 * * *' # nightly full pass, reports to the queue
jobs:
secrets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 } # scanners need history, not a merge snapshot
- run: gitleaks detect --source . --redact --exit-code 1
sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 } # diff-aware needs the merge base, not a snapshot
- run: semgrep ci --sarif --output=semgrep.sarif
env: { SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} }
deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v4 # fails on new vulns in changed lockfilesTwo details carry the load. fetch-depth: 0 gives the secrets scanner full git history — the default depth of 1 shows it a snapshot, not the commits. And the cron trigger is what covers "new CVE in old code": the diff you merged in March doesn't change, but a CVE published in November still applies to it.
The ordering rule
Fast and deterministic first, slow and probabilistic later. A PR check that takes twenty minutes or flakes half the time will be bypassed within a sprint — I've watched it happen at three different companies, and the developers were right every time. A control that can't keep its stage's latency budget belongs in the next stage, tuned down to advisory, or deleted.
Two controls don't fit the map cleanly and end up homeless. License scanning is a legal control, not a security one — run it on a schedule, never in the dev loop. Fuzzing is real security work but measured in CPU-hours; it lives in a dedicated job, feeding crashes into the same triage queue as everything else.
Field notes
- Run the same scanners in CI even where developers have pre-commit hooks. Hooks are opt-out; CI is not.
- Every stage reports to the same findings queue — SARIF into code scanning is the free version of that.
- If you can only afford one stage, make it the PR stage. It's the last point where fixing is still cheap.
- Budget each stage's wall-clock time and publish it — "PR checks complete in under 6 minutes" is a promise the pipeline has to keep, or the bypass metrics will tell you it didn't.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Buying Time: Package Managers Are Adding Delay as a Security Control
Composer 2.11 shipped a cooldown that refuses to install a version until it has aged. vlt now holds npm publishes until their dependencies actually exist, because 22% of new npm versions land broken. And Ruby Central's reviewers threw out 90% of what an AI scanner flagged.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.
CVE-2025-62718: Critical Axios SSRF Vulnerability Explained
A critical SSRF flaw in Axios was used in a North Korean supply chain attack. Here's what it does and how to patch it today.
What is Supply Chain Security? Dependencies, SBOMs, and the Attack That Hit 2.6 Billion npm Downloads
Your application is only as secure as every package it depends on. In September 2025, attackers compromised 27 npm packages with 2.6 billion weekly downloads by phishing one maintainer.