Security defects are defects, and the testing skills from this series apply to them: design test cases from requirements, automate what repeats, explore what doesn't, and keep a regression test for every fix. Security testing adds its own tools and one non-negotiable rule: test only what you're authorized to test. This lesson is the testing practitioner's view: how to run and combine static analysis, dependency and secret scanning, dynamic scanning, and security regression tests in a pipeline, how to triage what they report without drowning, and how to verify that the software you build and ship is what you think it is.
Before you start
You should be comfortable with CI quality gates from lesson 10 and fuzzing from Advanced Testing Techniques: Property-Based Testing, Fuzzing, and Mutation Testing. For the vulnerabilities themselves (injection, XSS, broken access control), our security series covers them in depth, starting from OWASP Top 10 Explained; this lesson links to it rather than repeating it.
Authorization comes first
Security testing tools send unusual and sometimes harmful input. Against a system you don't own, that's an attack, regardless of intent. Before any security test:
- Test your own code, local environments, and staging systems you control.
- For anything else, get written permission that states the scope (which hosts and accounts), the time window, and the allowed techniques.
- Use test accounts and test data, never real users' data.
- Tell the people who operate the system, so an alert doesn't trigger an incident response.
The OWASP Web Security Testing Guide is a good methodology reference for authorized testing.
The layers of automated security testing
Each tool type looks at software from a different angle, and each misses things the others catch:
- SAST (static application security testing) reads source code for dangerous patterns: SQL built by string concatenation, unsafe HTML rendering, disabled certificate checks. Examples: Semgrep, CodeQL. Fast, early, but prone to false positives and blind to runtime configuration.
- SCA (software composition analysis) checks your dependencies against databases of known vulnerabilities. Examples:
npm audit,pnpm audit,cargo audit,composer audit, OSV-Scanner, Dependabot alerts. - Secret detection finds credentials in code and history. Examples: Gitleaks, platform secret scanning and push protection.
- DAST (dynamic application security testing) probes the running application from outside, like an attacker would: missing security headers, exposed files, some injection points. Example: OWASP ZAP. It sees real behavior but not the code, and covers only what it can reach.
- Fuzzing (lesson 13) for crashes in code that parses untrusted input.
- Security regression tests: your own tests, written for your application's rules. These find the most important class of bugs that scanners can't: logic and authorization flaws.
Dependency scanning in practice
Here's npm audit on a project that depends on an outdated version of a popular utility library:
# npm audit report
lodash <=4.17.23
Severity: high
Command Injection in lodash - https://github.com/advisories/GHSA-35jh-r3h4-6jhm
Prototype Pollution in lodash - https://github.com/advisories/GHSA-p6mc-m468-83gw
Regular Expression Denial of Service (ReDoS) in lodash - https://github.com/advisories/GHSA-29mw-wpgm-hmr9
...
fix available via `npm audit fix`
node_modules/lodash
1 high severity vulnerabilityThe report lists the affected versions, each advisory, and whether a fix is available. The same tools exist for every ecosystem:
npm audit --omit=dev --audit-level=high # fail CI only on high or critical, production dependencies
cargo audit # Rust, using the RustSec advisory database
composer audit # PHP
osv-scanner scan --lockfile=pnpm-lock.yaml # many ecosystems, using the OSV databaseRun them on every pull request and on a schedule: new advisories appear for code you haven't changed.
Triage: deciding what matters
Scanners produce many findings. Treating them all as urgent burns out a team; ignoring them all invites a breach. Triage each finding with a few questions:
- Is it real? SAST findings can be false positives: the "SQL injection" may use a value from a fixed allowlist. Confirm by reading the code path.
- Is it reachable? A vulnerable function in a dependency matters only if your code (or an attacker's input) can reach it. A vulnerability in a build-only tool is less urgent than one in your web server.
- How severe, and how likely? Severity scores such as CVSS describe impact; exploitation data (for example, whether it's in CISA's Known Exploited Vulnerabilities catalog, or its EPSS probability) indicates how likely it is to be used.
- What's the fix? Upgrade, patch, configure around it, or accept the risk with a written reason and a review date.
Record decisions, so the same false positive isn't re-investigated every week. Most tools support suppressing a specific finding with a comment or configuration entry; always include the reason.
Security regression tests
The most valuable security tests are the ones you write for your own rules, because no scanner knows that user A must not see user B's invoices. Write them like any regression test (lesson 5), at the lowest level that can catch the defect:
import request from "supertest";
import { describe, expect, it } from "vitest";
import { app } from "../src/app";
import { signInAs } from "./helpers";
describe("security regressions", () => {
it("doesn't let one customer read another's booking", async () => {
const ada = await signInAs("ada@example.test");
const res = await ada.get("/api/bookings/belongs-to-ben");
expect(res.status).toBe(404);
});
it("treats SQL syntax in search as plain text", async () => {
const res = await request(app).get("/api/classes").query({ q: "x' OR '1'='1' --" });
expect(res.status).toBe(200);
expect(res.body).toEqual([]);
});
it("encodes user input in the results page", async () => {
const payload = "<img src=x onerror=alert(1)>";
const res = await request(app).get("/search").query({ q: payload });
expect(res.text).not.toContain(payload);
});
it("never returns password hashes", async () => {
const ada = await signInAs("ada@example.test");
const res = await ada.get("/api/users/me");
expect(JSON.stringify(res.body)).not.toMatch(/passwordHash|\$argon2/);
});
});Every security bug fixed should add one. Over time, this file becomes a record of the attacks your application has learned to resist.
Dynamic scanning, safely
DAST tools run against a deployed environment. Start with a passive scan, which crawls and inspects responses without sending attacks; OWASP ZAP's baseline scan works this way and is safe for a staging environment you own:
docker run --rm -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t https://staging.your-app.test/Active scans send attack payloads and can change or delete data, so run them only against isolated test environments with disposable data, and never against production without explicit, planned authorization. Scanners mostly find configuration problems (headers, cookies, exposed paths); combine them with your regression tests for application logic.
Verifying the supply chain
The software you deploy is built from your code, your dependencies, and your build system. Verification asks: is this exactly what we intended to build and ship?
- Lockfile integrity: install with frozen lockfiles (
npm ci,pnpm install --frozen-lockfile,cargo build --locked), so CI tests exactly the versions developers reviewed. Lockfiles record integrity hashes, and installs fail if a downloaded package doesn't match. - Registry signatures:
npm audit signatureschecks that installed packages carry valid registry signatures and, where published, provenance attestations:
$ npm audit signatures
audited 1 package in 1s
1 package has a verified registry signature- SBOMs: generate a software bill of materials for each release, so you can answer "are we affected?" when a new vulnerability is announced.
- Build provenance: signed statements of what source and workflow produced an artifact. Verify them before deploying, for example with
gh attestation verifyfor GitHub artifact attestations orcosign verifyfor signed container images. - Deploy by digest: deploy the exact artifact that passed testing, identified by its hash, not a mutable tag.
The Software Supply Chain Security and Git Repository Security lessons cover how to set these up; from a testing perspective, the point is to make verification a failing check, not a manual step.
Security in code review
Automated tools run on every change; people review every change too. A short security checklist for reviewers catches what tools can't:
- Does every new endpoint check who the user is *and* whether they may act on this specific object?
- Is all untrusted input validated, and are queries parameterized?
- Is output encoded for its context, and is any HTML sanitized?
- Are new secrets loaded from configuration, never written in code or logs?
- Does a new dependency come from a trustworthy, maintained source?
Each "no" is either a fix or a test to write.
A security testing pipeline
Putting it together:
- On every pull request: SAST, secret detection, dependency scan of changed lockfiles, security regression tests.
- Nightly: full dependency scan, DAST baseline against staging, longer fuzzing runs.
- On release: SBOM generation, provenance attestation, signature verification before deploy.
- Periodically: manual review and exploratory testing of high-risk features (authentication, payments, file uploads), and penetration tests by people with security expertise.
Common mistakes and troubleshooting
- Scanning without authorization. Get written permission for anything you don't own.
- Trusting a clean scan. Scanners miss logic and authorization flaws; write regression tests for those.
- Alert fatigue. Triage by reality, reachability, severity, and exploitation, and record decisions.
- Blocking every pull request on any low-severity finding. Gate on high and critical; track the rest.
- Suppressing findings without a reason. Always document why, and set a review date.
- Scanning only on pull requests. New advisories appear daily; scan on a schedule too.
npm audit fix --forcewithout review. It can install breaking major versions; read what it changes and run your tests.
Practical exercise: a security testing baseline
On a project you own:
- Run the dependency scanner for your ecosystem, triage every high finding (real, reachable, severity, fix), and record decisions.
- Run a secret scanner over the full Git history.
- Write four security regression tests: one cross-account access check, one injection check, one output encoding check, and one sensitive-field check.
- Run a passive DAST baseline scan against a staging or local environment you control.
- Add the scans and tests to CI, failing only on high-severity findings, plus a weekly scheduled run.
- Run
npm audit signatures(or your ecosystem's equivalent) and generate an SBOM for the build.
Key takeaways
- Test only what you're authorized to test, with written scope for anything you don't own.
- Combine SAST, dependency scanning, secret detection, DAST, and fuzzing; each misses what others catch.
- Triage findings by whether they're real, reachable, severe, and likely exploited; record decisions.
- Security regression tests for your own rules catch the logic and authorization bugs scanners can't.
- Verify the supply chain with frozen lockfiles, signatures, SBOMs, and provenance, as failing checks.
References
- OWASP Web Security Testing Guide (opens in a new tab)
- npm Docs: npm audit (opens in a new tab)
- OSV-Scanner (opens in a new tab)
- RustSec: cargo-audit (opens in a new tab)
- ZAP: Baseline scan (opens in a new tab)
- Semgrep documentation (opens in a new tab)
- CISA: Known Exploited Vulnerabilities Catalog (opens in a new tab)
- FIRST: Exploit Prediction Scoring System (EPSS) (opens in a new tab)
What's next
The final lesson brings quality into production. Production Quality Engineering: Flaky Tests, Release Confidence, and Continuous Improvement covers risk-based strategy, flaky tests, release gates, and learning from incidents.

