The Vulnerability Class That Arrived With AI Coding Assistants

LLM-generated code passes syntax checks, passes type checks, and can still fail security checks. Here's why and what to do about it.

DevSecCode Team · · AppSec · 7 min read

The AI Code Quality Problem Is a Security Problem

Published studies have found security vulnerabilities in a meaningful share of LLM-generated code. An NYU study (Pearce et al., "Asleep at the Keyboard?") found about 40% of the programs GitHub Copilot generated across 89 security-relevant scenarios were vulnerable, and a Stanford user study (Perry et al.) found that participants with an AI assistant wrote less secure code.

This isn't a reason to avoid AI coding assistants. It's a reason to have write-time security scanning that runs on every line of code, regardless of whether a human or an LLM wrote it.

The Patterns AI Code Gets Wrong

Hardcoded Secrets (CWE-798)

LLMs generate example code with hardcoded API keys, passwords, and tokens. When that example code is accepted and committed, the secret is in the repository. AI coding assistants are now a meaningful source of CWE-798 findings in enterprise codebases.

# LLM-generated example. Commonly accepted without modification
API_KEY = "sk-prod-1234567890abcdef"
client = OpenAI(api_key=API_KEY)

Insecure Deserialization (CWE-502)

LLMs trained on older codebases reproduce pickle-based serialization patterns, yaml.load() without Loader argument, and other insecure deserialization patterns. These patterns were common in older Python code and are well-represented in training data.

SQL Construction from String Formatting (CWE-89)

When asked to write database queries, LLMs often produce string-formatted SQL unless explicitly instructed to use parameterized queries. The formatting looks clean in the completion, and developers accept it without recognizing the injection risk.

# Common LLM completion. Injectable
query = f"SELECT * FROM users WHERE username = '{username}'"
cursor.execute(query)

Missing Input Validation at API Boundaries (CWE-20)

LLMs generate complete API handlers that handle the happy path but omit input validation. The generated code is functional and passes tests against valid input, but doesn't validate type, length, format, or encoding.

The Trust Model Problem

AI coding assistants are trusted in a way that copy-pasted Stack Overflow code is not. When a developer pastes code from Stack Overflow, they often read it and modify it. When an LLM completes code inline, the natural tendency is to accept and move on.

This means AI-generated vulnerabilities have a higher probability of reaching production than manually introduced vulnerabilities, because they look authoritative and developers trust the completion.

The Compound Risk: AI + Speed

AI coding assistants increase developer velocity. More code ships per developer per day. Security review processes don't scale at the same rate. The net effect is a growing gap between code being written and code being reviewed. Exactly the gap that write-time scanning closes.

How Deva Addresses AI-Introduced Vulnerabilities

Deva scans code regardless of whether a human or an AI wrote it. The editor extension can scan on save, so issues surface while the change is still in front of you.

The vulnerabilities LLMs introduce are the same CWEs as always, just with a new source, so the same detection rules apply.

Frequently asked questions

Is AI-generated code more vulnerable than human-written code?
Published studies have found vulnerabilities in a meaningful share of LLM-generated code. An NYU study (Pearce et al., 'Asleep at the Keyboard?') found about 40% of the programs GitHub Copilot generated across 89 security-relevant scenarios were vulnerable, and a Stanford user study (Perry et al.) found that participants with an AI assistant wrote less secure code.
What vulnerabilities do LLMs commonly introduce?
Hardcoded secrets (CWE-798) in example code, insecure deserialization (CWE-502) from pickle and yaml.load patterns common in training data, string-formatted SQL queries (CWE-89) when developers do not ask for parameterized queries, and missing input validation at API boundaries (CWE-20).
Should I stop using GitHub Copilot or Cursor?
No. The productivity gains from AI coding assistants are real. The change is that write-time security scanning has to run on every line of code regardless of who or what wrote it. The combination is fast development and fast detection. Not slow development.
How do you scan AI-generated code for security issues?
Use a scanner that runs at write time, not just on commit or in CI. The same CWE detection rules that catch human-introduced vulnerabilities catch LLM-introduced ones, because the vulnerabilities are the same CWEs. The new requirement is the scan cadence: as code is generated, not after.

Related glossary terms