0000 · 0000

Dappasol / Guides

Updated June 2026

How to Scan AI-Generated Code: Semgrep vs Snyk

No single scanner is enough. Run a SAST tool (Semgrep or CodeQL) for code flaws, a software-composition scanner (Snyk) for vulnerable dependencies, and a secrets scanner (TruffleHog) for leaked keys, then a DAST pass with OWASP ZAP on the running app. Use two SAST tools, not one, because each catches what the other misses.

AI coding tools like Lovable, Bolt, Cursor, Replit and v0 ship code fast. The catch: they optimize for code that runs, not code that is safe. The holes show up in the same few places every time: trusted input, leaked secrets, vulnerable dependencies, and broken access control. So the answer is not one magic all-in-one scanner. It is a small pipeline of focused tools, each covering a layer the others can’t see. This guide walks the four scanner categories, when to run each, and the minimum pipeline we run before any AI-built app touches production.

Scanner comparison at a glance

Each tool below owns a different layer. You are aiming for coverage across all four, not crowning a single “best” tool.

ToolTypeCatchesGood for
SemgrepSAST (static analysis)Injection, insecure patterns, custom rules for your stackFast, low-noise scans and writing project-specific rules
CodeQLSAST (static analysis)Deep data-flow and taint-tracking vulnerabilitiesTracing how untrusted input reaches a dangerous sink
SnykSCA (software composition)Known CVEs in third-party and transitive dependenciesDependency vulnerabilities plus fix and upgrade advice
npm audit / pip-auditSCA (software composition)Known advisories for your package managerA free, fast first-pass dependency check
TruffleHog / gitleaksSecrets scannerAPI keys, tokens, and credentials in code and git historyCatching leaked secrets before they ship or after a leak
OWASP ZAPDAST (dynamic analysis)Runtime issues: XSS, misconfiguration, exposed endpointsProbing the running app the way an attacker would

SAST: scan the source for code flaws

Static Application Security Testing reads your source code without running it and flags the insecure stuff. This is where you catch injection, unsafe deserialization, weak crypto, and the dangerous shortcuts AI models reach for by default. Run two SAST tools, not one. They work differently and catch different things, so one alone leaves a hole.

Semgrep is quick and catches the obvious patterns. CodeQL is slower but actually reasons about data flow. Together you get breadth and depth. Run only one and the gap is predictable.

SCA: scan your dependencies

Software Composition Analysis checks the third-party packages your app pulls in against databases of known vulnerabilities. It matters more for AI-generated code, which imports packages freely and will happily suggest outdated or abandoned ones.

A vulnerable dependency is a vulnerability in your app even when your own code is flawless. So dependency scanning is not optional.

Secrets: scan for leaked keys

AI tools hardcode API keys and tokens all the time, or expose them to the client by slapping NEXT_PUBLIC_ or VITE_ on the front. A secrets scanner finds credentials sitting in your codebase and, the part people miss, buried in your git history where a clean working tree will never show them.

If a scan turns up a real secret, rotate it. A leaked key in git history is already compromised even after you delete the line, because the old commit still holds it.

DAST: scan the running app

Dynamic Application Security Testing hits the live, running application from the outside, the way an attacker would. It catches things that only show up at runtime and that static analysis simply cannot see: reflected and stored XSS, security misconfiguration, missing headers, and exposed endpoints.

OWASP ZAP is the standard open-source DAST scanner. Point it at your staging URL, let it spider the app and run active scans, then read what it surfaces. SAST and DAST cover for each other: SAST sees the code but not the deployed behavior, DAST sees the behavior but not the code. You want both before launch.

The minimum viable scan pipeline

Run these in order. The first four are the floor for any AI-built app heading to production. Do not skip the second SAST tool.

  1. SAST pass one (Semgrep). Fast scan of the source for insecure patterns and injection. Wire it into CI so it runs on every change.
  2. SAST pass two (CodeQL). Deeper data-flow and taint analysis to catch what pattern matching misses. Two SAST tools, not one.
  3. SCA (Snyk, plus npm audit or pip-audit). Scan direct and transitive dependencies for known CVEs and apply the suggested upgrades.
  4. Secrets (TruffleHog or gitleaks). Scan the working tree and full git history. Rotate anything real that turns up.
  5. DAST (OWASP ZAP). Run against a staging deploy to probe the live app for XSS, misconfiguration, and exposed endpoints.
  6. Human review. Scanners are blind to authorization and business logic. A person still has to confirm a user cannot read another user’s data by changing an ID, and that the payment flow is verified server-side.

Scanners catch known patterns. They do not catch logic flaws. For the manual side of this, see our guide on how to audit AI-generated code for security and the full pre-launch AI code security checklist. The single most common finding is leaked credentials, covered in exposed API keys in AI-built apps.

Want us to run this audit for you?

We do a free 15-minute build audit: you show us your AI-built app, we tell you the specific security and production gaps and what it takes to fix them. No obligation.

Book your free build audit

FAQ

What is the difference between Semgrep, Snyk, and CodeQL?

Semgrep and CodeQL are SAST tools that scan your own source code for flaws: Semgrep is fast pattern matching with custom rules, CodeQL does deep data-flow and taint analysis. Snyk is an SCA tool that scans your third-party dependencies for known CVEs. They cover different layers, so you run all three.

Is one scanner enough to secure AI-generated code?

No. SAST tools find code flaws but not vulnerable dependencies, SCA tools find dependency CVEs but not your code's bugs, secrets scanners find leaked keys, and DAST finds runtime issues. You need one of each, plus two SAST tools, because they catch different classes of vulnerability.

Why run two SAST tools instead of one?

SAST tools work differently and miss different things. Semgrep is fast pattern matching that catches obvious insecure code, while CodeQL traces how untrusted input flows to a dangerous sink. Run both and you get breadth and depth. Run one and you leave a predictable gap.

Do I still need manual review if I run all these scanners?

Yes. Scanners catch known patterns, but they are blind to authorization and business logic. A human still has to confirm a user cannot read another user's data by changing an ID, or that a payment amount is verified server-side. Use automated scans and human review together.

Book a free 15-min build audit →