Plausible is not safe
Lesson 1 of 27 · Why generated code fails · 2 min · Free Watch this lesson freeThe code runs. The tests pass. The demo works. And somewhere inside it is a line that lets any logged in user read every other customer's invoices.
That gap, between working and safe, is what this course is about. By the end you will review generated code the way an attacker reads it, and you will have checks that catch the repeat offenders for you.
What was measured
Veracode tested over a hundred language models, writing Java, Python, C sharp and JavaScript, on coding tasks built around well known weaknesses. In forty five percent of the samples, the code failed security tests and introduced a flaw from the OWASP Top 10.
Be careful how you repeat that. It is a rate from a controlled test, not a census of all the AI code in the world. Veracode also reported that security did not improve as models got better at writing code that works.
Why it is predictable
Here is my reasoning, not a finding. A model is rewarded for code that runs and looks like code it has seen. Your prompt asks for a feature, almost never for a threat model, so the safe version and the unsafe version both look finished.
And the model cannot see your boundaries. It does not know which route is public, which field a user may set, or which path came from the internet. Those facts live in your head, so the review has to supply them.
A model for review
So treat generated code as a pull request from a fast contributor who has never read your threat model. You would not merge that on trust, and you would not reject it on principle. You would review it, with questions.
Three questions cover most of what goes wrong. Who is allowed to call this? What input can an outsider control? And what does this code touch that would hurt if it were misused?
What to keep
Generated code is plausible by construction, so plausibility tells you nothing about safety. Safety comes from review that supplies the context the model lacked. Next, we turn those three questions into a habit you can run on any diff.
This is the narration of a video lesson from Secure the code AI writes. In the video it is animated, and you can pause it to ask a question.