RedFlag
All posts
·6 min read

The 7 most common security bugs in AI-generated code

AI coding tools ship features fast - and security holes just as fast. Here are the seven vulnerabilities that show up again and again in AI-written code, and how to catch them.

AI coding assistants are extraordinary at producing working code quickly. What they are not good at is producing secure code by default. A model optimises for 'does this run and pass the prompt', not 'is this safe against a motivated attacker'. The result: whole codebases that work perfectly in the demo and fall over the first time someone probes them.

After scanning thousands of repositories, the same handful of issues keep surfacing. Here are the seven most common - and the fastest way to find them before an attacker does.

1. SQL and NoSQL injection

The classic. AI frequently interpolates user input straight into a query string because that's the simplest way to satisfy a prompt like 'search users by name'. Anything built with string concatenation instead of parameterised queries is a candidate for injection.

// Vulnerable
db.query(`SELECT * FROM users WHERE name LIKE '%${req.query.q}%'`)

2. Missing authorization checks (broken access control)

Models are good at adding authentication ('is the user logged in?') and bad at authorization ('is this user allowed to do THIS?'). Endpoints that check for a session but never verify ownership or role lead directly to IDOR and privilege-escalation bugs - the single most common serious flaw we see.

3. Hardcoded secrets

API keys, database URLs, and tokens pasted directly into source. They work instantly, which is exactly why they get committed - and once they're in git history, they're effectively public forever.

4. Insecure deserialization and unsafe eval

Reaching for eval(), pickle.loads(), or unserialize() on untrusted input is a fast way to satisfy a 'parse this dynamic data' prompt and a fast way to hand an attacker remote code execution.

5. Server-side request forgery (SSRF)

Any feature that fetches a user-supplied URL server-side - webhooks, link previews, image proxies - is an SSRF risk if the URL isn't validated against an allow-list. Cloud metadata endpoints are the usual target.

6. Cross-site scripting (XSS)

dangerouslySetInnerHTML, v-html, and template rendering of unescaped input. AI reaches for these to render 'rich' content and quietly opens a script-injection hole.

7. Vulnerable dependencies

Models train on old code, so they frequently pin old, known-vulnerable package versions. A single outdated dependency can undo everything else you did right.

How to catch them

You don't need to memorise the OWASP Top 10 to stay safe - you need a review pass that actually reads your code the way an attacker would, across files, not just pattern-matching a linter. That's exactly what RedFlag does: point it at a repo and it returns every one of these issues, ranked by severity, with the file, the line, and a copy-paste fix.

Find these bugs in your own repo

Paste a GitHub repo and RedFlag returns every vulnerability, ranked, with a one-click fix. Your first scan is free.

Scan your repo