The Quiet Responsibility
S2 · Nº 07

5 MINMisha Tryndiuk

AI-generated code is safe, said no security researcher ever

The models write code that looks safer than it is: well formed, with error handling and validation in the obvious places, and systematic blind spots where it counts. Generated code inherits the internet’s average mistakes. Here are the three patterns review has to hunt for.

The well-dressed risk

AI-generated code looks safe. Well structured, try-catch in place, often with a validation or two in the obvious spots. It radiates competence. And the radiance lowers the guard of exactly the people who were meant to judge it.

But the model learned from the internet’s code. And the internet’s code holds decades of average mistakes: examples written for readability, not security; tutorials that skip authorization “for simplicity”; patterns that were acceptable in 2015.

Generated code inherits the average. Security rarely lives in the average.

Three systematic blind spots

The patterns repeat, and they are worth knowing by heart:

1. Validation of shape, not of trust. The model will happily validate that the email looks like an email and that the number is a number. It asks less often who is allowed: the authorization check – does the logged-in user actually own the resource being requested? – is easy to leave out, because it needs context about your access model that the model does not have. The code is well formed. The door is unlocked.

This is not a new or exotic class of bug. Broken Access Control sat at number one in the OWASP Top 10 in the 2021 edition, and still does in the 2025 edition. So it was the industry’s most common serious flaw already before anyone generated code. The models learned from code with the same weaknesses, and now reproduce them faster than before.

2. Secrets wherever it is convenient. Ask for an integration, and the example code tends to arrive with the key in a variable, in a config file, in cleartext, because that makes the example runnable. Under time pressure, runnable becomes committed. And committed is forever.

3. Dependencies from memory. The model suggests packages it “remembers”: some outdated, some with known vulnerabilities, and some that do not exist. That last one has become its own class of attack, with its own name: slopsquatting. And the research on it is uncomfortably concrete. In We Have a Package for You! (Spracklen et al., USENIX Security 2025) the researchers went through 576,000 generated code snippets from 16 models. 19.7 percent of the package recommendations pointed at names that do not exist – just over 205,000 unique invented package names.

The share matters less than the fact that the same names come back. When Spracklen’s team ran 500 prompts ten times each, 43 percent of the invented names came back in all ten runs, and 58 percent in total came back more than once. Only 39 percent never appeared again.

Another detail explains why they slip through review: most of the invented names are not misspelled real package names, but names that look plausible on their own. Only 13 percent are within one or two characters of a real name. And 8.7 percent of the invented Python packages are real packages, in JavaScript.

The spread between models has shrunk since, but the risk has not: a May 2026 replication (a single-author preprint), The Range Shrinks, the Threat Remains, measures 4.6 to 6.1 percent across five frontier models from 2025 to 2026 – about where the commercial models in the 2025 study already were, and none of them beats the best model from it – and finds 127 package names that all five invent identically. And upgrades are a trap of their own: Sonatype’s 2026 report gives a 27.76 percent hallucination rate for dependency-upgrade recommendations from a leading model – a different measure from invented package names, but the same pattern.

The repetition makes the attack trivial to plan. The attacker asks the model enough times, notes the names that do not exist, registers packages under the ones that repeat, and waits for someone else to get the same suggestion.

Note the difference from classic typosquatting: no typo is required from the developer here. The tool suggested the name, it looked right, and the install happened voluntarily.

The common thread: the flaws lie in what the code leaves out – the access check, the vault for the secret, a vetted package – and omissions are precisely what a fast review misses.

The defense: context in, skepticism out

Nobody needs to ban generation for this. It is enough to treat generated code as what it is: a suggestion from a capable stranger with no context about your system.

Give the model the security context. The context files in the repo should hold the security conventions: how secrets are fetched, how authorization is done in your system, which packages are approved. The same mechanism that works against all divergence – a suggestion that starts from the right context needs less rescuing in review. The context file is a hint, not a control; the check still happens in review and CI.

Review for what is absent. The five security questions apply twice over to generated code, especially question two: Who can call this – and is it checked in this code? Look for what is missing, not only for what is written.

And verify every suggested package. Does it exist – and has it for a while? Who publishes it, and how many people use it? Does the documentation of the library you actually wanted point to it? If you have an approved list or an internal registry mirror, the suggestion goes there first. Thirty seconds per package. Cheap insurance against an expensive class of bug.

Context before, skepticism after

AI-generated code is dangerous in a different way from human-written code: confidently incomplete, at scale, with a polished surface that disarms.

The antidote is the same as always, only more so: context before generation, skepticism after.

The code looks safe. Whether it is safe is decided by the five questions in review and by the thirty seconds per package name.