Why AI coding needs security as much as functionality 

AI-generated code security

AI coding assistants are now commonly used in software development, with AI responsible for roughly half of committed code. As organisations use these AI-powered tools to move faster and with greater agility, security must keep pace.

AI-generated code should not be treated differently to any other code that enters the development environment. It still needs to be tested, governed and secured.

However, the challenge is that code can function well and still be vulnerable. AI-generated code achieves a 99.9% pass rate for syntactic correctness, yet its security performance remains far lower. Around 44% of tested code-generation tasks introduce a known vulnerability, leaving the average security pass rate at just 56%. With software vulnerabilities now the top breach entry point, the gap between functional code and secure code is becoming a significant problem that organisations cannot afford to ignore.

The answer is to build security into the development process from the start. This means choosing models with security risk as a criteria and testing AI-generated code in the context in which it will actually run. When security happens alongside development rather than after it, organisations can maintain the speed and scale AI enables without allowing security debt to build up.

Security decisions begin with model selection

AI models learn from significant volumes of historical and publicly available code, including examples from open-source projects and developer communities. That training data contains secure implementations, but it also contains outdated libraries, weak validation and insecure coding patterns. While models are designed to produce useful, functional code, without the right controls they can reproduce those insecure patterns at scale.

Businesses cannot control every source used to train a model, but they can control which models enter development. Analysis reveals that the strongest model tested achieved a 68% security pass rate, while six of the 11 models clustered between 50% and 53%. Model selection is, therefore, not just a productivity decision but a risk consideration.

Selecting a more secure model can reduce exposure, but it does not make the output trustworthy by default. AI-generated code should still be tested throughout the software development lifecycle using capabilities like static analysis, dynamic analysis and enforceable security policies.

Context is the key to security

When AI-generated code successfully passes functional tests, security vulnerabilities can be masked and left undetected. Under deadline pressure, that creates misplaced confidence, particularly when developers accept output without fully understanding how it behaves inside the wider application.

The contrast in security performance across vulnerability types shows why context matters. While models achieved pass rates of 83% for SQL injection and 87% for insecure cryptographic algorithms, performance fell to 15% for cross-site scripting and 12% for log injection. Some weaknesses can be identified through a recognisable coding pattern, but others often depend on data flows, authorisation, trust boundaries and how different parts of an application interact.

"If security can keep pace with development, teams can get the productivity benefits of AI-generated code without creating larger problems further down the line."

Verification needs to happen within the workflow and in the context of the application. AI-native analysis can add contextual risk detection alongside established static analysis, surfacing issues such as logic flaws and broken authentication directly in pull requests. The key is to combine contextual analysis with independent testing before code is merged and vulnerabilities build up.

But identifying and fixing vulnerabilities is only part of the challenge. Organisations also need to consider how to limit their impact if exploited. This means taking a ‘resilient by design’ approach, building in controls that restrict access, limit permissions and prevent attackers from moving across systems. This ensures that a single vulnerability does not lead to a wider breach.

Closing the gap between discovery and remediation

While AI increases the volume and speed of software development, the amount of risk security teams have to assess and remediate also increases. That adds additional pressure to organisations that are already carrying significant backlogs of unresolved vulnerabilities.

These unaddressed vulnerabilities allow security debt to build as flaws are identified but remain unfixed. The more that debt accumulates, the harder and more expensive it becomes to reduce. Today, security debt affects 82% of organisations, while critical security debt – flaws that remain unfixed for longer than a year -impacts 60% of enterprises.

The challenge is that organisations are generating and discovering risk faster than they can reduce it. Treating every finding as equally urgent only exacerbates the problem. Instead, security teams must identify the business’ ‘crown jewels,’ the applications and systems that handle sensitive data, support essential services or play a critical role in daily operations.This will put them in a stronger position to focus on directing limited remediation capacity towards the vulnerabilities most likely to cause serious harm.

To close the gap between discovery and action, AI-powered remediation can propose fixes directly within developer workflows, reducing repetitive manual work. It can also help close the gap between discovery and action by proposing fixes inside the developer workflow and reducing repetitive manual work. But remediation still needs to be governed. A generated fix must be tested, validated and checked for regressions. The objective should be to reduce meaningful exposure, not simply increase the number of findings or fixes moving through the system.

Next steps for leaders

AI-generated code is accelerating how organisations develop software. But the next step is making sure security is built into the process from the outset rather than being treated after the fact.

It’s imperative that leaders have visibility into where AI-generated code is entering the organisation, how different models perform from a security perspective, and which checks are in place before that code reaches production. They also need a clear record of what has been tested, what has been fixed and where risk has been consciously accepted. This approach makes it easier to focus security resources on the issues that could have the greatest impact.

Rather than slowing down AI adoption, the right controls enable organisations to move quickly without allowing unnecessary risk to amass in the process. If security can keep pace with development, teams can get the productivity benefits of AI-generated code without creating larger problems further down the line.

Chris Wysopal, Co-founder & Chief Security Evangelist at Veracode

Chris Wysopal

Chris Wysopal is Co-founder and Chief Security Evangelist at Veracode, where he helps shape conversations around cybersecurity best practices, strengthens industry engagement and builds relationships with customers and security professionals. Before establishing Veracode in 2006, Chris served as Vice President of Research and Development at cybersecurity consultancy @stake, which was later acquired by Symantec.

Author

Scroll to Top

SUBSCRIBE

SUBSCRIBE