Skip to main content
Back

Study Finds AI Coding Assistants Fail Security in 45% of Tasks Across Languages

A new benchmark of 200 tasks across 4 languages and 5 models reveals that LLM-generated code is riddled with outdated cryptography, buffer overflows, and hard-coded secrets — and the language you pick matters enormously.

Pro

Paper, Full Access
  • Language matters most: Python and Java generate safer, more correct code than C and C++, where buffer overflows and cryptographic misuse dominate.
  • Crypto is broken everywhere: RSA without OAEP padding (CWE-780) and hard-coded credentials (CWE-259) appear across all five models and all four languages.
  • Models ignore modern APIs: Despite running on Java 17 and C++17, LLMs default to legacy random number generators and deprecated cryptographic methods.
  • Claude-3.5 and GPT-4o lead: Claude-3.5 tops semantic correctness in three of four languages; llama-3 scores as low as 72.9% in C.
  • 4,000 unit tests, 97K lines analyzed: The open dataset covers 200 tasks across 5 models × 4 languages, evaluated with SonarQube and CodeQL plus manual review.
  • Baseline for the field: The model-agnostic framework is designed for future studies to plug in new models and track security progress over time.

AI coding assistants are now embedded in nearly every stage of software development, but a sweeping new study from researchers at the University of Central Florida and Birzeit University puts a hard number on how much you should trust what they generate. The answer: it depends heavily on which language you're targeting, and the security gaps are more systematic than random.

The paper, titled Security and Quality in LLM-Generated Code: A Multi-Language, Multi-Model Analysis, is one of the most comprehensive evaluations of its kind. It pits five major LLMs against 200 programming tasks across Python, Java, C++, and C, then runs every output through compilation checks, 4,000 hand-written unit tests, and two static analysis tools: SonarQube and CodeQL. The result is a 97,412-line dataset of generated code with every security finding catalogued and manually verified.

The language gap is real and quantifiable

The most striking finding is not that LLMs generate insecure code , that has been known for years. Multiple benchmark studies have reported that a substantial fraction of generated code snippets, ranging from 12% to 65% depending on the task, language, model, and prompting configuration, are non-compliant with basic secure coding standards or explicitly trigger CWE-classified vulnerabilities. What this paper adds is a precise, cross-language breakdown of where the failures concentrate.

Python and Java achieve higher compilation and semantic correctness rates and produce fewer security findings than C and C++, where memory safety issues, hard-coded secrets, and cryptographic misuses are more prevalent. The gap is not subtle. Semantic correctness (whether the code actually does what it is supposed to do) for the best-performing model, claude-3.5, drops from 92.1% in Python to 84.2% in C. For llama-3, the worst performer in C, it falls to 72.9%.

Five models, one benchmark, no prompt engineering

The five models evaluated were GPT-4o, claude-3.5-sonnet, gemini-1.5-pro, codestral, and llama-3. Crucially, all inputs used the original task descriptions without prompt engineering , mimicking how a typical developer would actually interact with these tools. This is a meaningful design choice: prompt-engineered results tend to flatter models, while raw prompts expose the defaults.

The 200 tasks were manually curated and span seven categories:

  • Secure Coding , tasks grounded in MITRE's CWE taxonomy (102 tasks), covering injection flaws, cryptographic misuse, and insecure data handling
  • Data Structures and Algorithms , sorting, graph traversal, recursion (86 tasks)
  • Parsing and Validation , input processing and boundary checking (54 tasks)
  • Networking , authentication errors and protocol misuse (48 tasks)
  • Mathematics and Logic (26 tasks)
  • Programming Systems and Utilities , file handling, scripting (18 tasks)
  • Concurrency and Synchronization , race conditions, thread safety (6 tasks)

Each task was adapted into a language-neutral specification so the same logical problem could be tested in all four languages, enabling direct apples-to-apples comparison. The team then wrote 4,000 individual unit test files , one per generated program , requiring over 800 person-hours of manual work across five months.

The vulnerability patterns are language-specific

The security findings break down along clear language lines, and the patterns are actionable:

  • Java: The dominant vulnerability is CWE-780 , RSA encryption without OAEP padding. Every model generates this flaw frequently. When asked to implement RSA, models call Cipher.getInstance("RSA") and default to the insecure PKCS1 v1.5 padding scheme, which is vulnerable to padding oracle attacks. Hard-coded passwords (CWE-259) and improper XML entity handling (CWE-611, enabling XXE attacks) are also common.
  • Python: Similar cryptographic misuse persists, along with hard-coded credentials and cross-site scripting vulnerabilities (CWE-79). Python's simplicity helps with compilation and correctness but does not translate into secure defaults.
  • C++: Cryptographic weaknesses dominate , improper certificate validation (CWE-295), inadequate encryption strength (CWE-326), and broken algorithms (CWE-327). The paper also flags outdated random number generation: models routinely use srand(time(0)) and rand() instead of the modern <random> header available since C++11.
  • C: Buffer overflows take center stage. CWE-120 (buffer copy without size checking) is the most frequent finding, followed by incorrect buffer size calculations (CWE-131) and out-of-bounds memory access (CWE-788). These are the classic memory safety issues that C demands manual vigilance against, and LLMs consistently fail to provide it.

Here is a concrete example of the RSA problem the paper documents, generated by GPT-4o for a Java encryption task:

// CWE-780: RSA without OAEP padding
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
KeyPair pair = keyGen.generateKeyPair();
// Insecure: defaults to PKCS1 v1.5, vulnerable to padding oracle attacks
Cipher encryptCipher = Cipher.getInstance("RSA");
// Secure alternative would be:
// Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding")

Models are stuck in the past

One of the more damning findings is that many models fail to make use of modern security features available in recent compiler and toolkit updates, such as Java 17, and that outdated methods remain common, particularly in C++. Despite the evaluation environment using OpenJDK 17 and C++17, models gravitate toward legacy APIs. In Java, this means using older random number generation instead of the cryptographically secure alternatives introduced in recent versions. In C++, it means reaching for rand() over std::mt19937 or std::random_device.

This is not a minor stylistic issue. LLMs produce security flaws because their training data may encompass insecure code while their understanding of secure coding principles remains insufficient. The models are essentially pattern-matching against the most common examples in their training data, which skews toward older, pre-modern-standard code.

Who performs best?

Across the board, claude-3.5 and GPT-4o lead on compilation success and semantic correctness. Claude-3.5 achieves the highest semantic correctness in Java (91.8%), Python (92.1%), and C++ (91.2%). GPT-4o is the strongest in C++ compilation (89%) and shows the most balanced profile across languages.

On the security side, gemini-1.5 exhibited the highest overall reported vulnerabilities, suggesting less conservative or secure default behaviors. Codestral tends to generate shorter, simpler code with fewer maintainability issues, which correlates with fewer security hotspots. Llama-3 consistently underperforms in lower-level languages, with C semantic correctness bottoming out at 72.9%.

ModelPython Semantic %Java Semantic %C++ Semantic %C Semantic %
claude-3.592.191.891.284.2
GPT-4o90.988.388.081.1
gemini-1.590.589.581.077.0
codestral88.682.983.773.7
llama-388.581.679.372.9

What this means in practice

The paper is a measurement study, not a fix. But its findings have direct implications for teams using AI coding assistants today:

  • If you are generating C or C++ with LLMs, treat every memory operation as suspect. Buffer overflow patterns are systematic, not occasional.
  • Any cryptographic code generated by an LLM , in any language , should be reviewed against current standards before use. RSA without OAEP and hard-coded credentials are near-universal failure modes.
  • Python and Java outputs are more likely to compile and pass functional tests, but they are not free of security issues. The lower-hanging fruit (correctness) being solved does not mean the harder problem (security) is.
  • Prompt engineering was deliberately excluded here. Adding security-specific instructions to prompts has been shown in other work to reduce vulnerabilities, and this study's baseline numbers represent the worst-case default behavior.

AI-generated code introduced security vulnerabilities in 45% of coding tasks across more than 100 LLMs, according to the 2025 Veracode GenAI Code Security Report , a figure that aligns with the failure rates documented here. The problem is not going away on its own, and this paper gives the community a reproducible baseline to track whether it improves.

The dataset is open

All code, data, prompts, and unit tests are available on GitHub, including the 4,000 generated programs and their static analysis results. The evaluation framework is model-agnostic, designed so that future studies can swap in new models by updating only a thin API adapter layer. That makes it a living benchmark rather than a one-time snapshot , which matters a lot given how fast the underlying models are changing.

The authors are explicit that their results represent a time-stamped view of current model behavior. Model rankings will shift as vendors update their systems. But the structural patterns , C and C++ lagging Python and Java, cryptographic misuse persisting across all languages, legacy APIs dominating over modern secure alternatives , are likely to remain stable challenges until training pipelines are explicitly designed to prioritize secure coding practices over raw functional correctness.