Lesson 4 of 12 · 22m
SAST: Static Analysis That Doesn't Cry Wolf
Static analysis is the workhorse of shift-left and its biggest noise source — the job isn't running Semgrep, it's curating what it's allowed to say.
A fresh Semgrep run on a mature codebase will cheerfully report thousands of "findings," most of them technically correct and practically irrelevant. Running the tool is the easy half — anyone can semgrep scan --config auto and present the number as an accomplishment. The real work is the tuning loop that turns that firehose into ten findings a sprint that people fix.
What SAST actually does
Static analysis pattern-matches your source against known-bad shapes: string-concatenated SQL, eval(), innerHTML fed by user data, weak crypto, dangerous deserialization. The better tools do interprocedural dataflow — Semgrep's taint mode and CodeQL follow a value from req.query into a db.query sink across several files, which is what separates them from grep with anxiety.
What it's good at:
- "Never do X" rules:
eval(userInput),child_process.execwith concatenation,document.write, MD5 for anything but checksums. - Framework misuse: missing CSRF middleware,
DEBUG = Truein a Django settings file,verify=Falseon arequestscall. - Custom rules for your codebase — the underused superpower. Your ORM's footguns, your internal auth helper invoked with the wrong scope.
What it's bad at — the wrong mental model is "coverage," as if a clean scan means safe code:
- Business-logic flaws. No scanner finds "user can refund other users' orders." There is no pattern for your authorization mistake.
- Anything assembled at runtime: config composed at deploy, reflection, dynamic
require, plugin loaders. DAST and review cover that side.
A custom rule is five lines of YAML
# .semgrep/no-sql-concat.yaml
rules:
- id: sql-concat-query
patterns:
- pattern: db.query($A + $B, ...)
- pattern-not: db.query("..." + "...", ...)
message: "Use parameterized queries — see security/sql.md"
severity: ERROR
languages: [javascript]semgrep scan --config .semgrep/ --config p/javascript --error--error makes findings exit non-zero — that's your gate. p/javascript pulls the community pack from the registry; the local directory adds house rules. A rule named after your own codebase's conventions outperforms a generic pack in signal-to-noise every time, because it encodes context a registry author never had. metavariable-regex and pattern-either get you most of what CodeQL's query language does for the common cases, without a PhD in .ql.
Reading the output like an engineer
SAST findings arrive with a severity, a confidence, and a dataflow path — read the path, not the severity. req.params.id reaching db.query through a sanitization layer the tool can't model is a false positive worth suppressing; req.body reaching exec with no validation is a real bug at "medium." --autofix rewrites some finding classes automatically — use it for the mechanical ones (deprecated APIs, unsafe defaults), never for anything touching auth or data.
The tuning loop that works
- Run full-repo, advisory only. Read the top twenty findings by hand.
- Disable rule families that are pure noise for your stack — a Java deserialization rule in a Node shop earns nobody anything.
- Triage the rest: real bugs get tickets; accepted ones get
// nosemgrep: rule-id -- reason, reviewed like code. - Only then enable blocking — and only on rules you've vetted.
Field notes
nosemgrepsuppressions require a justification in the comment and get reviewed like code — they're an audit trail, not an escape hatch.- Language coverage is the hidden gotcha: a "multi-language" tool may have deep rules for Java and three for Go. Check rule counts for your stack before buying.
- Diff-aware scanning (
semgrep ci) is what belongs in PRs; full-repo scans are scheduled work. CodeQL's GitHub integration does the same split throughcodeql-action/analyze. - Track false-positive rate per rule, not per tool. One noisy rule family generates most of the pain — delete the rule, keep the tool.
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.