arXiv:2610.08240cs.SEOct 2026

Manuscript Offprint

arXiv:2610.08240

Newer and Bigger, but Safer? A Longitudinal Study of the Functionality-Security Gap in LLM-Generated Code

Thiago Santos de Moura, Fynn Matuschek, Flavio Toffalini, Yannic Noller

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

THIAGO SANTOS DE MOURA, Ruhr-Universität Bochum, Germany

FYNN MATUSCHEK, Ruhr-Universität Bochum, Germany

FLAVIO TOFFALINI, Ruhr-Universität Bochum, Germany

YANNIC NOLLER*, Ruhr-Universität Bochum, Germany

Large Language Models (LLMs) are widely used to generate code. Although their functional plausibility keeps improving, the generated code often contains security vulnerabilities. The functionality-security gap captures code that passes functional tests but fails security tests. A recent longitudinal study of three model families concluded that LLMs become smarter but not safer, with the only considered open-weight family stagnating. Whether this holds for other (open-weight) families and particularly for compact models remains open. We present a longitudinal study of the gap across 32 LLMs from seven model families (five open-weight), covering three successive releases per family in flagship and compact variants. Using CWEval with 119 tasks in five programming languages and 31 CWEs, we compare trajectories across families, model sizes, and languages. Newer models do become safer in absolute terms, although no family closes the gap. Unlike prior work, we find that openness does not separate the families: every considered open-weight family narrows the gap significantly, while Gemini 3.1 Pro keeps a gap as wide as the one reported for Llama. Compact models usually produce less secure code than their flagship counterparts, with notable exceptions (e.g., Gemini 3.7 Flash). At the CWE level, we confirm persistent weaknesses such as log injection (CWE-117) and HTTP response splitting (CWE-113) and regressions in the newest proprietary models on memory and integer weaknesses, and show that the same CWE carries very different risk across languages. From these results, we derive implications for LLM vendors, researchers, and developers. In particular, developers should assume neither that upgrades improve security nor that proprietary models are more secure; they should rerun security checks after each model change and provide secure APIs in the model's context.

1 Introduction

Large Language Models (LLMs) have become part of everyday software development. Code generation is the most studied use of LLMs in software engineering [23], and coding assistants such as OpenAI Codex [44] and Gemini CLI [18] increasingly generate and modify code on behalf of developers. To choose among the many available models, practitioners rely on leaderboards [70]. For coding, these rank models mainly by how often their code passes functional tests, as on SWE-bench [25], LiveCodeBench [24], and HumanEval [5], and even these rankings are fragile: small variations in benchmark problem formulations can largely affect the final rank [70]. The consideration of security properties of the generated code rarely enters such rankings. Early studies found that about 40% of the programs generated by GitHub Copilot were vulnerable [50] and that only 5 of 21 programs written by ChatGPT were secure without further prompting [28]. Critically, such code flaws do not remain isolated, but they reach public GitHub projects [13], code generated by ChatGPT is merged into open-source projects [63], and developers who use an AI assistant write

*Corresponding author: yannic.noller@acm.org

Authors' Contact Information: Thiago Santos de Moura, Ruhr-Universität Bochum, Bochum, Germany, thiago.santosdemoura@acm.org; Fynn Matuschek, Ruhr-Universität Bochum, Bochum, Germany, fynn.matuschek@rub.de; Flavio Toffalini, Ruhr-Universität Bochum, Bochum, Germany, flavio.toffalini@rub.de; Yannic Noller, Ruhr-Universität Bochum, Bochum, Germany, yannic.noller@acm.org.

  1. This is the author's version of the work. It is posted here for your personal use. Not for redistribution. The definitive Version of Record was published in , https://doi.org/10.1145/nnnnnnn.nnnnnnn.

Thiago Santos de Moura, Fynn Matuschek, Flavio Toffalini, and Yannic Noller

less secure code while being more confident in its security [52]. Novices in particular overestimate the reliability of AI output and spend less time verifying it [62].

Although the security properties of generated code are paramount interest, current related studies evaluate the models available at one point in time [27, 65, 67], and security benchmarks rank models only once [21, 51, 64, 66, 68]. Models, however, change with every new version [4, 32], and a property that changes over time can only be understood by following it across versions [26], as a recent review of AI assistance also calls for [62]. A snapshot cannot tell whether a newer version that writes better code also writes more secure code, or whether an upgrade reintroduces weaknesses that its predecessor had avoided. Currently, the community lacks a robust methodology to assess whether families of models are improving the security properties of their generated code, and if such improvements are biased toward specific issues or programming languages.

Cannavale et al. [3] took a first step toward answering this question. They measure the functionality-security gap, the difference between how often a model generates functionally plausible code and how often that code also passes a set of security tests. They follow it over four versions each of GPT, Claude Sonnet, and Llama on CWEval [51], whose dynamic oracles judge functionality and security on the same program. They conclude that models become “smarter, but not safer”: the gap narrows for the two proprietary families but not for Llama. However, their design captures only part of how current models evolve. In particular, we identified three limitations. First, they evaluate one tier per family, although vendors offer smaller and cheaper models next to their flagships, which developers may choose to reduce costs or to run a model locally. Second, their open-weight side is Llama alone, so the contrast between proprietary and open-weight models rests on a single family, while families such as Qwen, DeepSeek, Z.ai, Moonshot, and MiniMax have become competitive on coding benchmarks. Third, they examine programming languages only as a robustness check, through a single gap per language that averages over all weaknesses, although the weaknesses of generated code differ by language [27].

In this paper, we propose a new model methodology to assess how models of different nature (e.g., open vs closed, flagship vs compact) change their performance over time and across languages. To achieve our goal, we study the functionality-security gap across 32 models from seven families, two proprietary (Google and OpenAI) and five open-weight (Qwen, DeepSeek, Z.ai, Moonshot, and MiniMax), over three successive versions (stages) each and, where a family offers one, at both a flagship and a compact tier. With 100 samples for each of the 119 CWEval tasks per model, we analyze 380,800 programs to answer the following research questions:

RQ 1_{1} (Gap Trajectory) How does the functionality-security gap evolve across the stages of a model family?

RQ 2_{2} (Model Tiers) How does the functionality-security gap differ between the flagship and the compact model of a family?

RQ 3_{3} (CWE Evolving Behavior) Which CWE categories persist, diverge, or regress as model families evolve?

RQ4 (Programming Languages) How do CWE categories differ across programming languages?

Our results show that newer models do become safer in absolute terms: in every family, the newest stage produces more code that is both functionally plausible and secure 1^{1} than the first. Every family also narrows the gap significantly by its newest stage for at least one number of attempts per task, but none closes it. Where functional plausibility grows almost as fast as security, the gap can persist, as for Google, whose newest stage does not narrow the gap significantly when models get a single attempt ( RQ1RQ_{1}). When the tiers differ significantly, the compact model is almost always less secure, a penalty that shrinks as families evolve ( RQ2RQ_{2}). Log injection (CWE-117) and HTTP

1^{1}We consider a code as secure if it passes a set of targeted security tests, following the practice of CWEval [51] (Section 3.2).

Newer and Bigger, but Safer? A Longitudinal Study of the Functionality-Security Gap in LLM-Generated Code

3

response splitting (CWE-113) remain insecure in most models, other categories divide the families regardless of whether their weights are open, and the newest models regress on vulnerability categories that their predecessors had already handled ( RQ3RQ_{3}). Finally, the risk of a category depends strongly on the language, and C has the highest vulnerability rate in most models ( RQ4RQ_{4}).

These results refine and extend the findings of Cannavale et al. [3] in three ways. First, openness does not separate the families: every open-weight family narrows its gap significantly, while the newest Google flagship keeps a gap as wide as the one reported for Llama. Developers can therefore consider open-weight models without assuming a security penalty. Second, a cheaper tier is not a fixed security cost, since the compact penalty shrinks over stages and some compact models match their flagships (e.g., Gemini 3.7 Flash). Third, while the gap of each family evolves similarly across languages, individual CWEs do not: the same CWE carries different risks in different languages, so the best model choice can depend on the language and on the weaknesses one cares about most.

Our results carry direct implications. Vendors should report security scores next to functional ones and compare each new version with its predecessor per weakness type, since an aggregate improvement can hide a regression. Developers should not treat an upgrade or a cheaper tier as neutral for security, and they can steer models toward secure code by placing secure APIs in the prompt context, since models follow the path that the prompt or the library offers. Researchers should report results for multiple attempts per task and for more than two versions per family (trajectories), since both choices matter. In summary, we make the following contributions:

  • A longitudinal study of the functionality-security gap across 32 LLMs from seven families over three stages, including a comparison of flagship and compact models within each family.

  • An analysis of how CWE categories persist, diverge, or regress across stages, and how their risk varies across programming languages.

  • A comparison with prior work showing that openness does not determine the security trajectory of a model family.

• Actionable implications for model vendors, developers, and researchers.

• A replication package with the generated code, execution results, and analysis scripts.

References (15)