Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
AI coding assistants produce working code quickly and insecure code just as quickly. The measured defect rates, and the controls that catch them, matter more than the debate.

Is AI-Generated Code Secure?
AI coding assistants write code that compiles, passes the obvious tests, and looks like something a competent developer produced. Whether it is secure is a separate question, and the published evidence is consistent: a meaningful proportion of generated code contains recognised vulnerability patterns, and developers using assistants are more likely to believe their insecure code is safe.
The first systematic look came from New York University in 2021, where researchers generated code for scenarios drawn from the MITRE CWE list and found that around 40% of the completions in security-relevant contexts contained a vulnerability. A Stanford study published in 2023 ran a controlled experiment: participants with an AI assistant wrote less secure solutions to several tasks than those without one, and rated their own answers as more secure. Veracode’s analysis of generated code published in 2025 reported that roughly 45% of samples introduced a weakness from the OWASP Top 10, with cross-site scripting and log injection among the worst-performing categories. The numbers vary with model and prompt, but the direction does not.
Models are trained on public repositories, including a great deal of tutorial code written to be short rather than safe, and on examples that were secure against the threats of their era. Several failure patterns recur:
A distinct and more exploitable problem is the package that does not exist. Assistants regularly import libraries they have invented, and the same invented names recur across runs rather than appearing at random. Attackers register those names on public registries and wait, a technique the Python ecosystem named slopsquatting in 2025 after research measured how often recommended packages were non-existent. The defence is mechanical rather than educational: resolve all dependencies through an internal proxy or allow-list, fail the build on an unknown package, and review every new dependency in a pull request as a change of its own.
Treat assistant output as a contribution from an unknown external developer who is fast, confident, and has not read your threat model. That framing produces the right controls. Require human review of every generated change, with the reviewer told which parts were generated, because people skim code that looks finished. Run static analysis and software composition analysis in the pipeline and block on high-severity findings rather than reporting them. Keep secret scanning on the pre-commit hook as well as the pipeline. Add security-relevant tests—authorisation checks, input boundaries, error paths—since generated unit tests tend to cover the happy path the generator had in mind. The OWASP Top 10 remains the working checklist, and our note on secure software development covers the surrounding process.
Two non-security risks travel with the code. Licensing exposure arises when a model reproduces substantial portions of training data under a copyleft licence, which is why enterprise tiers offer filtering and indemnities worth reading carefully. Confidentiality exposure arises when proprietary code is sent to a hosted service; check whether the provider trains on submissions and whether an enterprise tenancy with retention controls is available. Where generated code processes personal data, UK GDPR’s security obligation under Article 32 applies exactly as it does to hand-written code, and the ICO will not distinguish between the two after a breach. Set the rules in your AI usage policy and verify them in the pipeline. At Privia Security, our Web Application Security Services test the applications that result, whoever or whatever wrote them.
Most teams should not, because the productivity gain is real and the risks are manageable with pipeline controls. The failure mode is adopting the assistant without changing review practice. If every generated change goes through human review, static analysis, dependency allow-listing, and secret scanning, the residual risk is comparable to code written quickly by a junior developer.
The techniques are the same, but the emphasis shifts. Prioritise authorisation logic, input handling, and cryptographic choices, because those are where generated code fails most often. Pay particular attention to new dependencies, and avoid relying on tests the same assistant wrote, since they tend to encode the generator’s assumptions rather than challenge them.
Deliberately, not on its own. The realistic routes are indirect: a hallucinated package name that an attacker has registered, or instructions hidden in a repository file or issue that a coding agent reads and acts on. Both are addressed by controlling dependency resolution and by treating repository content an agent processes as untrusted input.
The organisation that shipped it. No current provider accepts liability for security defects in output, and UK GDPR, PCI DSS, and contractual security obligations all attach to the deploying organisation. In practice this means your definition of done, your review gates, and your evidence of testing need to cover generated code explicitly.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.