Platform Engineering · Lesson 254

Application Security Testing in the Pipeline: SAST, SCA, Secrets, IaC, Containers, DAST, and Prioritisation

Security testing works best as a set of fast, specific checks in the same pipeline that builds the code, each catching a different kind of flaw: secret detection (keys committed by mistake), SAST (static analysis of your code), SCA (known vulnerabilities and licences in dependencies), IaC scanning (misconfigured Terraform and Kubernetes), container scanning (vulnerable packages in images), and DAST (attacking the running app). The hard part is not running scanners; it is prioritising thousands of findings so engineers fix what is exploitable and reachable first, using exploit data (CISA KEV, EPSS) and context. This lesson follows one pull request through the security checks, and shows the two failures that make scanning useless: a scanner wall nobody reads, and a severity score treated as a priority.

Difficulty: Advanced · Know this first: Lesson 241, Lesson 244

What you will learn

By the end of this lesson you can work at four levels:

This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar adds up minutes the security checks add to a pull request, including the fixes. It is a worked example, not a measurement. The prioritisation hop decides whether the checks protect anything.

Try it: triage the findings

Pick how findings are prioritised, what blocks a merge, and whether scanners are deduplicated. The readouts show what an engineer sees and what ships.

43findings an engineer sees
2blocking
noexploitable flaw ships?

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

Application security testing grows in four levels: reading findings, running the checks, prioritising by risk, and running a vulnerability management programme.

Basic — Read findings

At the basic level you can read a finding and fix it.

  • What secrets, SAST, SCA, IaC, container, and DAST checks each look at.
  • A finding's rule, location, and suggested fix.
  • CVSS, CVE, and why a fixed version matters.

Where it breaks: suppressing a finding without a reason.

Try it: Basic

SAST flags a query built with string formatting. What is the fix?

Now do it: Find a string-built query in a codebase you know.

Intermediate — Run the checks

At the intermediate level you wire the checks into the pipeline.

  • Secret scanning with push protection; SAST on the diff; SCA with lock files.
  • IaC scanning on the plan; container scanning and SBOMs on the image.
  • DAST nightly against staging.

Try it: Intermediate

Why run IaC scanning on the Terraform plan rather than the source files only?

Now do it: Run Checkov on a plan file.

Advanced — Prioritise by risk

At the advanced level findings are ranked by likelihood and impact.

  • KEV membership, EPSS probability, reachability, exposure, data sensitivity, fix availability.
  • Deduplication across scanners; suppressions with reason and expiry.
  • A short blocking list; deadlines by risk tier for the rest.

Try it: Advanced

What does EPSS estimate?

Now do it: Look up the EPSS score of a CVE in your dependencies.

Master — A vulnerability management programme

At the master level vulnerabilities are managed as a measured programme.

  • SLAs by risk tier (KEV: days; high reachable: weeks); time-to-fix tracked.
  • Automated dependency updates (Renovate, Dependabot) to keep the backlog small.
  • Security champions in teams; findings in normal backlogs; trends reported.

Trade-off: strict gates slow some merges; a short, real blocking list keeps them respected.

Try it: Master

The vulnerability backlog grows every month. What reduces it most sustainably?

Now do it: Turn on automated dependency updates for one service.

Go deeper

The checks as pipeline steps (GitHub Actions syntax; the same tools run in any CI). Pin action and tool versions you have reviewed.

jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: {fetch-depth: 0}
      - name: Secrets (whole history of the pull request)
        run: gitleaks git --log-opts="origin/main..HEAD" --redact --exit-code 1
      - name: SAST on the diff
        run: semgrep scan --config p/default --baseline-commit origin/main --error
      - name: SCA from the lock files
        run: osv-scanner scan --lockfile package-lock.json --lockfile go.sum
      - name: IaC on the Terraform plan
        run: terraform -chdir=infra plan -out tfplan && terraform -chdir=infra show -json tfplan > plan.json && checkov -f plan.json --framework terraform_plan
      - name: Image scan and SBOM
        run: |
          docker build -t app:pr .
          trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 0 --format json -o trivy.json app:pr
          syft app:pr -o cyclonedx-json > sbom.json

A risk score for triage, in words: start with must-fix if the CVE is on the CISA KEV list and the code is reachable; otherwise rank by EPSS probability, raised for internet exposure and sensitive data, lowered when the vulnerable code is not reachable or only in test dependencies; use CVSS to break ties. Deduplicate findings for the same CVE and package across scanners before ranking.

DAST against staging: docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t https://staging.example.com runs a passive baseline scan; full active scans and API scans from an OpenAPI spec need an environment you own and are allowed to attack.

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. The warning among four thousand.

Timeline

  • Day 0A pull request adds an internet-facing export endpoint using a CSV library. SCA reports the library's known-exploited parser flaw, as finding 2,917 of 4,200 in the build log. The build is green.
  • Day 42Attackers send crafted files to the export endpoint and read other customers' export files from storage.
  • Day 44Unusual storage reads trigger an alert. The endpoint is disabled, the library upgraded, credentials rotated, and affected customers notified.

What changed after

Findings are deduplicated and ranked by KEV, EPSS, reachability, and exposure; the merge gate blocks on a short list of real risks; everything else gets a deadline by tier; and automated dependency updates keep most libraries current.

Try it yourself, from scratch

Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.

Before you start: A virtual environment for Python packages: python3 -m venv ~/sec && . ~/sec/bin/activate. Then pip install pip-audit, and Git. The key below is a made-up example in the documented AWS example format, not a real credential.

1. Linux commands

Type each one, read what it prints, and compare it with the note above it.

  1. Commit a fake key, then "remove" it in the next commit.

    Reversible

    mkdir -p ~/labs/sec && cd ~/labs/sec && git init -q
    echo "aws_access_key_id = AKIAIOSFODNN7EXAMPLE" > config.ini && git add . && git commit -qm "add config"
    echo "aws_access_key_id = ${AWS_KEY}" > config.ini && git commit -qam "remove key"
    cat config.ini

    Expect: The current file no longer contains the key.

    Clean up: rm -rf ~/labs/sec.

  2. Search the whole history the way a secret scanner does: the key is still there.

    Read-only

    git log -p --all | grep -nE "AKIA[0-9A-Z]{16}"

    Options: -p shows every change; --all every branch; the pattern matches AWS access key IDs.

    Expect: A line with AKIAIOSFODNN7EXAMPLE from the first commit: deleting a secret does not remove it from history, so a real one must be rotated.

  3. Scan pinned dependencies for known vulnerabilities (SCA).

    Reversible

    printf "requests==2.19.0\njinja2==2.10\n" > requirements.txt
    pip-audit -r requirements.txt --no-deps 2>/dev/null | head -12

    Options: -r reads a requirements file; --no-deps audits only what is listed. pip-audit queries the PyPI and OSV advisory data.

    Expect: Several known vulnerabilities with IDs and fixed versions for these old releases: the input to triage.

2. Python: triage.py

This program merges findings from three scanners, removes duplicates, and ranks them two ways: by CVSS score alone, and by risk (known exploitation on the CISA KEV list, EPSS probability, reachability, and internet exposure, with CVSS only breaking ties). It then applies a short blocking list for the merge gate. Save it as triage.py, then run it.

# triage.py
FINDINGS = [  # (scanner, cve, package, cvss, kev, epss, reachable, internet_facing, fix_available)
    ("sca",    "CVE-2026-1101", "csvparse",   7.5, True,  0.71, True,  True,  True),
    ("trivy",  "CVE-2026-1101", "csvparse",   7.5, True,  0.71, True,  True,  True),
    ("sca",    "CVE-2026-2202", "testfaker",  9.8, False, 0.02, False, False, True),
    ("trivy",  "CVE-2026-3303", "libxml",     8.1, False, 0.04, True,  False, True),
    ("sca",    "CVE-2026-4404", "imagekit",   6.5, False, 0.33, True,  True,  True),
    ("semgrep","SQLI-new-code", "exports.py", 8.0, False, 0.00, True,  True,  True),
    ("trivy",  "CVE-2026-5505", "zlib",       5.3, False, 0.01, False, False, False),
]
unique = {}
for f in FINDINGS:
    unique.setdefault((f[1], f[2]), f)
print(f"{len(FINDINGS)} findings from 3 scanners -> {len(unique)} after deduplication\n")

def risk(f):
    _, cve, pkg, cvss, kev, epss, reach, internet, fix = f
    score = epss * 10 + (5 if reach else -5) + (3 if internet else 0)
    if kev and reach:
        score += 100
    if cve.startswith("SQLI"):
        score += 50                                   # high-confidence SAST finding in new, internet-facing code
    return (score, cvss)

def blocks(f):
    _, cve, _, cvss, kev, _, reach, _, fix = f
    return (kev and reach and fix) or cve.startswith("SQLI") or (cvss >= 9 and reach and fix)

for name, key in (("by CVSS only", lambda f: f[3]), ("by risk", risk)):
    order = sorted(unique.values(), key=key, reverse=True)
    print(name + ":")
    for f in order:
        tag = "BLOCK" if name == "by risk" and blocks(f) else ""
        print(f"  {f[1]:<14} {f[2]:<11} CVSS {f[3]:>4}  KEV {'yes' if f[4] else 'no ':<3}  EPSS {f[5]:.2f}  reachable {'yes' if f[6] else 'no '}  {tag}".rstrip())
    print()

Run it, and you should see this output:

$ python3 triage.py
7 findings from 3 scanners -> 6 after deduplication

by CVSS only:
  CVE-2026-2202  testfaker   CVSS  9.8  KEV no   EPSS 0.02  reachable no
  CVE-2026-3303  libxml      CVSS  8.1  KEV no   EPSS 0.04  reachable yes
  SQLI-new-code  exports.py  CVSS  8.0  KEV no   EPSS 0.00  reachable yes
  CVE-2026-1101  csvparse    CVSS  7.5  KEV yes  EPSS 0.71  reachable yes
  CVE-2026-4404  imagekit    CVSS  6.5  KEV no   EPSS 0.33  reachable yes
  CVE-2026-5505  zlib        CVSS  5.3  KEV no   EPSS 0.01  reachable no

by risk:
  CVE-2026-1101  csvparse    CVSS  7.5  KEV yes  EPSS 0.71  reachable yes  BLOCK
  SQLI-new-code  exports.py  CVSS  8.0  KEV no   EPSS 0.00  reachable yes  BLOCK
  CVE-2026-4404  imagekit    CVSS  6.5  KEV no   EPSS 0.33  reachable yes
  CVE-2026-3303  libxml      CVSS  8.1  KEV no   EPSS 0.04  reachable yes
  CVE-2026-2202  testfaker   CVSS  9.8  KEV no   EPSS 0.02  reachable no
  CVE-2026-5505  zlib        CVSS  5.3  KEV no   EPSS 0.01  reachable no

3. What to notice

4. Advanced: every step as one Bash script

The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/application-security-testing-sast-dast-sca-and-iac-scanning && cd ~/labs/application-security-testing-sast-dast-sca-and-iac-scanning) and save this as lab.sh.

#!/usr/bin/env bash
# The Linux steps of "Application Security Testing in the Pipeline: SAST, SCA, Secrets, IaC, Containers, DAST, and Prioritisation", as one script (save it as lab.sh).
#
#   ./lab.sh          run every step, in order
#   ./lab.sh 2 4      run only steps 2 and 4
#   ./lab.sh --list   list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.

STEPS=(
  'Commit a fake key, then "remove" it in the next commit.'
  'Search the whole history the way a secret scanner does: the key is still there.'
  'Scan pinned dependencies for known vulnerabilities (SCA).'
)

step_1() {
mkdir -p ~/labs/sec && cd ~/labs/sec && git init -q
echo "aws_access_key_id = AKIAIOSFODNN7EXAMPLE" > config.ini && git add . && git commit -qm "add config"
echo "aws_access_key_id = ${AWS_KEY}" > config.ini && git commit -qam "remove key"
cat config.ini
}

step_2() {
git log -p --all | grep -nE "AKIA[0-9A-Z]{16}"
}

step_3() {
printf "requests==2.19.0\njinja2==2.10\n" > requirements.txt
pip-audit -r requirements.txt --no-deps 2>/dev/null | head -12
}

# print a step that has to be run by hand, instead of running it
by_hand() {
  echo "  (run this one yourself: $1)"
  sed 's/^/    /'
}

RESULTS=()
run_step() {
  local n=$1 start=$SECONDS code
  printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
  "step_$n"
  code=$?
  RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}

summary() {
  echo
  echo "== summary"
  local r
  for r in "${RESULTS[@]}"; do echo "  $r"; done
}

case "${1:-}" in
  -h|--help) sed -n '2,6p' "$0"; exit 0 ;;
  --list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac

[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
  if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
    echo "there is no step '$n'; try --list" >&2
    exit 2
  fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done

Then make it executable and run it:

chmod +x lab.sh
./lab.sh --list     # the steps
./lab.sh            # every step, then a summary of exit codes and times
./lab.sh 2 3        # only steps 2 and 3

5. Learn the basics behind it

New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.

If you remember nothing else

Design exercise

Your 40 services produce 60,000 open scanner findings and engineers ignore them. Design the application security testing and vulnerability management process.

Clarifying questions to ask

Which checks run where, and how fast? How are findings deduplicated and ranked? What blocks a merge? What deadlines apply by tier? How do you shrink the backlog sustainably? How do you measure progress?

Rough sizing

Say 40 services, 5 scanners, 60,000 open findings, 300 merges a week, and a security team of 4.

Shape of the answer

Push protection for secrets; SAST on the diff with tuned rules; SCA from lock files with reachability where available; IaC scanning on plans; image scanning and SBOMs; nightly DAST on staging; all findings into one platform with deduplication; ranking by KEV, EPSS, reachability, exposure, then CVSS; a gate that blocks only secrets, KEV or critical reachable with fixes, new high-confidence SAST, and IaC policy; deadlines by tier (KEV 7 days, high 30, medium 90); Renovate on every repository; security champions per team; monthly trend reports.

Trade-offs to name

A short blocking list accepts some lower risks for a while and keeps the gate respected; reachability analysis is incomplete for some languages; automated updates need good tests to merge confidently.

Failure modes and how to troubleshoot them

Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.

ScenarioWhereEffectWhat goes wrong
Scanner wallHop 8: PrioritisationBreaksEvery scanner's output goes into the build log: 4,200 findings per build, most low or duplicated, all labelled "warning". Engineers stop reading. The CSV library flaw, on the KEV list and reachable from the new internet-facing endpoint, ships.
CVSS as priorityHop 8: PrioritisationBreaksPriority is the CVSS base score. The team spends five weeks on CVSS 9.8 findings in test-only dependencies that never ship.

How to troubleshoot

  1. Write down the symptom and when it started: what users see, which number moved, and what changed just before (a deploy, a config change, traffic).
  2. Walk the path in order, from the first hop to the last: Threat model → Secret detection → SAST → SCA → IaC scanning → Container scan → DAST → Prioritisation → Security gate. The first hop whose evidence is wrong is where to dig.
  3. At that hop, run the read-only check from the diagram or the lab first; change nothing until the evidence points at a cause.
  4. Fix the smallest thing that restores service, or roll back the last change, and confirm the symptom is gone with the same check.
  5. Write down what you found and the check that would have caught it sooner, so the next person starts there.

References and review

The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.

Last updated . Next review due by November 2027. Found something out of date? Tell me.

Saved on this device, in this browser.
Next in this series · Lesson 255
Runtime Detection, Cloud Posture, Compliance as Code, and Security Evidence

Pipelines stop known-bad code from shipping; they cannot see what happens after. Runtime detection watches running workloads (Falco and other eBPF-based sensors read system calls: a shell spawned in a container, a write to /etc…

Go to Lesson 255 →

Or browse the full course from the Lessons index.