Part II β The Shield Β· Lesson 4.7
Security Testing
In one lineAutomate the scans that never get done manually, and put them in the pipeline as gates.
Where you've seen itThe merge that gets blocked because a transitive dependency picked up a known-critical CVE overnight.
Diagram
GATES ALONG THE PIPELINE β each catches a different class
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββ
β commit βββΊβ PR βββΊβ build βββΊβ staging βββΊβ prod β
ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββ
β β β β β
secret scan SAST + SBOM + DAST scan header
(no keys in dep audit license (running monitor +
the diff) (static code check app, real pentest
+ CVEs) requests) (periodic)SAST vs DAST vs SCA β three different questions
SAST reads your source "is this pattern dangerous?"
fast, early, noisy finds: innerHTML sinks, eval, secrets
DAST attacks the running app "does this actually exploit?"
slow, late, accurate finds: missing headers, XSS, CSRF,
auth bypass
SCA reads your lockfile "is a dependency known-bad?"
instant, high signal finds: CVEs in your 1,200 packagesSEVERITY GATE β block on reachable, schedule the rest
critical/high + reachable in prod code βββΊ FAIL the build
high, dev-dependency only βββΊ ticket, next sprint
moderate/low βββΊ batch monthly
no fix available βββΊ document + compensating
controlHow it works
- Secret scanning at commit (gitleaks, pre-commit hooks) β the cheapest possible catch, before the key ever reaches the remote.
- SCA on every PR β
npm audit, Dependabot, Snyk β gated on severity and reachability (see 3.7). - SAST on changed files only, so the run stays fast and the signal stays readable.
- DAST against staging β OWASP ZAP baseline covers missing security headers, obvious injection, and cookie flags in minutes.
- Test your own controls: assert in CI that CSP, HSTS, and
SameSiteheaders are actually present on responses.
// a security assertion is just a test
test('security headers present', async () => {
const res = await fetch(BASE_URL);
expect(res.headers.get('content-security-policy')).toBeTruthy();
expect(res.headers.get('strict-transport-security')).toMatch(/max-age=\d{7,}/);
expect(res.headers.get('x-content-type-options')).toBe('nosniff');
});Trade-offs
| Tool | Speed | False positives |
|---|---|---|
| Secret scan | instant | low |
| SCA / dependency audit | seconds | medium (reachability) |
| SAST | minutes | high β tune it or it gets ignored |
| DAST | minutesβhours | low |
| Manual pentest | days | lowest, and finds logic flaws |
Interview angle
"How do you test security in a frontend pipeline?"
- Layer it: secrets at commit, dependencies and SAST on PR, DAST on staging, header assertions as ordinary tests.
- Gate only on reachable high severity, or the team learns to bypass the gate entirely.
- Automation finds known patterns; business-logic flaws β like an IDOR on an order id β still need a human.
Recap
- Automate the boring scans and put them where they block, not where they nag.
- SAST reads code, DAST attacks the app, SCA reads your lockfile β you need all three.
- Header presence is testable; write it as a normal assertion.