The question I wanted answered was narrow. When a scanner stays green, which kinds of bug is it actually silent about? So I wrote 32 small Python files, ran three scanners on them, and counted.
Here's the part to read twice. Those files are mine. I wrote the vulnerable ones deliberately, in textbook shapes, and no model generated them. Nothing below is recall on AI-written code. It's a small illustration of how rule-based scanners fail, on code where I know the truth.
What did I run, exactly?
Eight CWE classes: 89 (SQL injection), 78 (command injection), 22 (path traversal), 79 (cross-site scripting), 502 (unsafe deserialization), 798 (hardcoded credentials), 327 (weak password hash) and 862 (missing authorization). Each class got four files:
- direct: the request value reaches the dangerous call in one function.
- indirect: it passes through a helper in the same file first.
- far: the helper sits in another module.
- safe: the same feature, written properly.
That's 24 vulnerable files and 8 safe ones. The direct and indirect SQL cases look like this:
# direct
row = conn.execute(f"SELECT id, email FROM users WHERE name = '{name}'").fetchone()
# indirect
sql = build_lookup(request.args.get("name", "")) # helper returns the string
row = conn.execute(sql).fetchone()
I ran Semgrep 1.182.1 (Community Edition) with p/python and p/security-audit, Bandit 1.9.4 with defaults, and CodeQL CLI 2.27.3 with codeql/python-queries 1.8.13 and its python-security-extended suite, all on 23 October 2026 on one Mac. A scanner "detects" a vulnerable file when it reports a finding of the matching CWE in that file or in the helper it imports. It "false-alarms" when the same kind of finding lands on the safe twin. The scoring script, the fixtures and the raw result file are in the blog's examples/what-semgrep-and-codeql-miss-in-python-code-by-cwe folder.
What did each scanner catch?
| CWE | Semgrep | Bandit | CodeQL |
|---|---|---|---|
| 89 SQL injection | 2/3 | 3/3 | 3/3 |
| 78 command injection | 3/3 | 3/3, 1 false alarm | 3/3 |
| 22 path traversal | 1/3 | 0/3 | 3/3, 1 false alarm |
| 79 cross-site scripting | 1/3, 1 false alarm | 0/3 | 3/3 |
| 502 unsafe deserialization | 3/3 | 2/3 | 3/3 |
| 327 weak password hash | 2/3 | 2/3 | 3/3 |
| 798 hardcoded credentials | 0/3 | 2/3 | 0/3 |
| 862 missing authorization | 0/3 | 0/3 | 0/3 |
| Total | 12/24 | 12/24 | 18/24 |
The surprise is what's missing, not what's there. Semgrep added zero files to CodeQL's 18. Every file Semgrep flagged, CodeQL flagged too. Whatever Semgrep's pattern rules know, CodeQL's data flow already covered on this set.
Why does Semgrep fall from 6 to 2 when a helper appears?
Semgrep's documentation says the Community Edition "can only analyze interactions within a single function". Cross-function and cross-file analysis belong to the paid engine. My numbers match that sentence almost mechanically: 6 of 8 direct files, 2 of 8 indirect ones.
Look at which two survived. Both were sink-only rules: subprocess with shell=True, and pickle.loads. They don't need to know where the value came from, so a helper in between costs them nothing. The same logic explains why Semgrep flagged the far yaml.load and the far SHA-1 file. Rules that need a source and a sink in one function (path traversal, XSS, most SQL injection) went quiet the moment I moved the string-building into a helper.
CodeQL held at 6 of 8 in every shape. Its data flow follows the value across functions and modules, so a detour isn't a hiding place. That's the whole argument for a flow-aware engine, and I'd say it plainly: if your gate runs only single-function pattern rules, you're measuring the easy half of your code.
Which classes did nobody see?
CWE-862 went 0 for 3 across every configuration, and I'd have been surprised by anything else. A missing-authorization bug isn't a dangerous call. It's an absent if. No rule can flag the lack of a check unless it knows which check your app was supposed to have. OWASP ranks broken access control first in its 2025 list and says all tested applications had some form of it. That's the class where tests and review have to do the work, which is the argument of five defects no linter could flag.
CWE-798 is the more instructive miss, because a rule exists. CodeQL ships py/hardcoded-credentials. It's tagged low precision, and the security-extended suite I ran didn't report it. Run alone, it flagged 2 of my 3 files: the literal password in a connect() call and the fallback value in os.environ.get. It missed the token in a settings dict. Semgrep's python and security-audit packs flagged none, and a separate run of p/secrets returned nothing on all 40 files, probably because my fake strings don't resemble real token formats. Bandit flagged two by variable name.
A green scan is a statement about the rules you ran. Whether it says anything about your code depends on which classes those rules model.
Add the low-precision credentials query and CodeQL reaches 20 of 24. Add Bandit and the union is 21. The cheapest gain in this whole run was a query CodeQL already ships, left out of the suite by default. That beats installing a second scanner.
What looked wrong in the findings themselves?
Four small things, all from the raw output.
- One Semgrep rule,
tainted-sql-string, is about SQL injection by its id and message, but its registry metadata says CWE-704, "Incorrect Type Conversion or Cast". I counted it as CWE-89 by reading it. A dashboard that filters on the CWE tag would have dropped the only Semgrep finding on my far SQL file. - Bandit flagged
PASSWORD_ALGO = "sha1"as a hardcoded password (B105), because of the variable's name. It also raised B603 on the safe, argument-listsubprocesscall. - CodeQL reported
py/path-injectionon my safe path file, which resolves the path and checksis_relative_tobefore reading. I didn't dig into why. My guess is that it doesn't treat that check as a sanitiser. - Semgrep flagged the safe XSS file, which wraps the value in
markupsafe.escape, with the same rules as the vulnerable one.
One false alarm per tool on eight safe files isn't a rate. It's a reminder that "flagged" and "right" are different columns.
What do published numbers say about this?
Not much that transfers, and I'd rather say so. CASTLE, a 2025 benchmark of 250 hand-crafted C programs over 25 CWEs, reports CodeQL 2.20.1 at 29 percent recall (45 of 150) and Semgrep Code 1.110.0 at 23 percent. That's C, not Python, and not AI-generated. My 18 of 24 for CodeQL is far higher, which tells you my fixtures are easy: a framework source, a plain sink, no build step, no ORM.
Dai, Xu and Tao argue that secure-code-generation papers lean on CodeQL alone, and that CodeQL misses several vulnerabilities, which blurs the security gains those papers report. Veracode's spring 2026 update, a vendor report scanned with its own tool, puts models at 82 percent secure on SQL injection and 15 percent on XSS across 80 tasks. Is it a coincidence that XSS is also where Semgrep flagged one of my three files? I wouldn't build a theory on it. But it's the pair of numbers I'd test next on real model output.
What would I put in a gate?
I'd keep this short and boring:
- One planted bug per CWE class you care about, in a fixtures folder, and a CI step that fails if the scanner stops flagging it.
run_scan.pyis that shape. It catches the quiet failure described in the lint rule that never ran: a rule that stopped doing anything while the check stayed green. - Pinned scanner and ruleset versions. The Semgrep registry is live, so my numbers can move on a later day. A CodeQL update can move alerts with no commit at all.
- Read the rule metadata before you build a dashboard on its CWE tags.
- Tests for authorization, written by a person: can user A read user B's invoice?
- A dedicated secrets scanner, because scanners tuned for injection weren't tuned for secrets.
- A look at what happens after a finding fires. A finding only helps if it gets fixed, and an agent's SAST finding handling covers the choice between silencing it and fixing it.
None of that replaces a reviewer. The twelve-gate list has SAST at number six, and this run is the reason not to stop there. To see which gates your pipeline file lacks, the CI gate audit will list them.
What are the limits of all this?
Plenty. n is 24 and 8. The fixtures are mine. I ran Semgrep's free engine, not its paid one with cross-function analysis, so the indirect gap may shrink with it. I didn't scan any model-generated code or any public benchmark corpus. The CodeQL licence permits research, demonstrating the software and open-source analysis, so I ran it only on these fixtures, outside any private code. The Semgrep rules fall under a licence that forbids redistributing them, which is why the example folder holds rule ids and no rule text.
The claim I'd stand behind is the small one. A green scan is not a verdict. It's a coverage statement, and on this set the coverage had a hole the shape of an absent if.