Manuscript Offprint

arXiv:2610.26001

SPLASH: Contrastive Audit Pressure for Detecting and Localizing Security Hallucinations in Generated Code

Mirza Masfiqur Rahman, MD Ajwad Akil, Imtiaz Karim, Ashish Kundu, Ramana Kompella, Elisa Bertino

MIRZA MASFIQUR RAHMAN*†, Purdue University, USA

MD AJWAD AKIL, Purdue University, USA

IMTIAZ KARIM, University of Texas at Dallas, USA

ASHISH KUNDU, Cisco Research, USA

RAMANA KOMPELLA, Cisco Research, USA

ELISA BERTINO, Purdue University, USA

Code generated by large language models often passes every functional test while remaining insecure. These security hallucinations are common, written with high confidence, and repeated across samples, so neither the generator's own uncertainty nor static analyzers reliably catch them. We introduce SPLASH, which is guided by a new measure called audit pressure. It contrasts teacher-forced log-probabilities for the generated program under a security review and a style review. Aggregated to statements and programs, and grounded in a probabilistic model of competing edits, audit pressure allows SPLASH to choose the secure program among a model's candidate programs and locate the vulnerable statement, with no model training, CWE-specific rules, or internal access to the generating model. On 63,684 programs generated by 12 models for 899 tasks, SPLASH picks secure code in 74% of cases, places the vulnerable statement first in 58% of insecure programs, and chooses better than a frontier LLM judge.

CCS Concepts: • Security and privacy → Software and application security.

Additional Key Words and Phrases: Code Generation, Security, Hallucination, Large Language Models

1 Introduction

Large language models (LLMs) [8, 14, 36] now produce syntactically and functionally correct programs from natural-language specifications and are widely integrated into commercial development workflows [27, 41]. The standard practice for validating generated code is functional testing: if the program passes its test suite, it is considered ready to deploy. However, a program can satisfy every functional requirement while containing a security vulnerability that no unit test exercises.

A model asked to hash a user’s password may write sha256(pw) without a salt: the code compiles, returns the expected digest, and passes the unit test. The secure alternative, bcrypt with a random salt, is rarely among the model’s likely continuations. This is a security hallucination [5, 44] (Definition 2.1): a functionally correct program that fails its security test. For capable models, the same model that writes unsalted SHA-256 can identify the flaw when asked to review it, showing that the security knowledge is present but remains inactive during generation. Security hallucinations are also produced with high confidence and reproduced consistently across independent samples, making them invisible to methods that rely on output variation.

Security hallucinations are common. Among working programs from open-weight models in our evaluation, 24–60% fail their security tests. Frontier models are safer (Claude Opus 5: 6%, GPT-5.6 Sol: 8%), but agentic pipelines retain roughly a third of their working solutions insecure.

∗^{*}Preliminary work done during internship at Cisco Research

†^{\dagger}Corresponding author

Authors' Contact Information: Mirza Masfiqur Rahman, rahman75@purdue.edu, Purdue University, West Lafayette, Indiana, USA; MD Ajwad Akil, makil@purdue.edu, Purdue University, West Lafayette, Indiana, USA; Imtiaz Karim, imtiaz.karim@utdallas.edu, University of Texas at Dallas, Richardson, Texas, USA; Ashish Kundu, ashkundu@cisco.com, Cisco Research, San Jose, California, USA; Ramana Kompella, rkompell@cisco.com, Cisco Research, San Jose, California, USA; Elisa Bertino, bertino@purdue.edu, Purdue University, West Lafayette, Indiana, USA.

Rahman et al.

DeepSeek-Coder-6.7B, “evaluate a user’s math expression” (SecCodePLT, CWE-94)

Figure

Fig. 1. A working but insecure program. DeepSeek-Coder-6.7B evaluates the user's expression with eval (line 12; CWE-94), which passes the unit tests and fails the security test. Left: the writer's own uncertainty peaks on the blocklist (line 5), not on the flaw; audit pressure (our method) peaks on line 12. Right: at line 12 the security reviewer expected a comment before return (91%) and (ast after eval (74%), and gave the program's own tokens under 1%; the style reviewer gives them far more (2% and 51%).

Such frequent nature and confident behavior of the models positions it as a critical concern in software development lifecycle.

Limitations of existing approaches. Hallucination detectors for natural language measure variation in the generator's output distribution [7, 16, 18, 23, 25], but security hallucinations violate their shared assumption as 86% of insecure working programs have only insecure siblings, and generation uncertainty is weak (AUROC 0.61). Static analyzers [4, 34, 38, 47] produce a CWE-matched finding on only 15% of security hallucinations. Generation-time defenses [11, 12, 48] reduce vulnerability rates by 25–35% but require training access and do not eliminate hallucinations. Post-hoc methods such as process reward models [49] and steering vectors [37] need labeled data and white-box access. LLM-as-judge approaches can name flawed lines but give no graded score to rank candidates and cost an API call per program.

Research challenges. Three properties make security hallucinations resistant to the approaches above. (C1) The generator’s own token distribution carries little signal about security: when code is written with near-zero entropy, the tokens reveal negligible information about any downstream property (Proposition 2.2). (C2) The vulnerability is typically an absence rather than a presence (missing validation, omitted salt), so there is no token to flag. (C3) Whether code is insecure depends more on the task than on the model (57% of variance vs 6%), so absolute scores do not transfer across tasks for any judge. SPLASH therefore asks the two questions a developer actually has: which candidate should I keep, and which line should I review?

Our approach. We present SPLASH (Statement-level Pressure Localization via Audit against Security Hallucinations). At its core is audit pressure, a novel method that reads the model's distribution under review (addressing C1): an auditor model reads a candidate program under two instructions, a security-review and a style-review, and the program is scored token by token via teacher forcing with nothing sampled. The method records positive audit pressure wherever the security reviewer would have written different code but the style reviewer is far more willing to reproduce the token. Because teacher-forced copying reveals where the reviewer wanted to

SPLASH: Contrastive Audit Pressure for Detecting and Localizing Security Hallucinations in Generated Code

3

insert code, the pressure of a missing check lands on the line where it would have been written (addressing C2). Figure 1 shows the concept: on eval(math_expr), the security reviewer expected (ast after eval, i.e. parsing the input safely, while style reviewer accepts it far more readily.

The per-token log-probability difference between the two instructions decomposes exactly into a log Bayes factor by the chain rule. Under a formal model of competing edits ( §4§4), this token-level pressure aggregates to statement scores and program scores with a probabilistic interpretation. The decomposition enables two outputs from the same pass: (1) selecting the most secure candidate (by lowest program score) and (2) localizing the vulnerable statement (by highest statement score). Because only within-task comparisons are needed, the task-level shifts that defeat cross-task classification do not affect either output (addressing C3). SPLASH applies to code from any source - open-weight models, closed-API models, and agentic pipelines, with no training, no CWE-specific rules, and no labeled data.

In practice. Security tests do not exist in ordinary development as they must be written per task by someone who already knows the vulnerability. Developers have, at most, unit tests. Although we use security tests in our evaluation to measure effectiveness of SPLASH], it does not rely on them as inputs. Meanwhile, sampling several candidates is already a common practice (IDE suggestions, best-of-k, agent retries), but there is no established way to choose among them for security. Audit pressure fills this slot as it requires no training, no per-CWE rules, no generator weights, and no paid API. It works with whatever unit tests exist and also without any (Figure 5b), and points the reviewer at the line; e.g., the vulnerable statement is in the top 3 in 85% of cases.

Findings. We evaluate SPLASH on 899 tasks with executable security tests across 12 generators:

• Selection. SPLASH picks secure code in 74% of decisive candidate pools (random: 54%, uncertainty: 65%), closing 46% of the gap to a perfect pick. On held-out tasks, the gain is within two points. On agentic code, SPLASH picks secure in 76% of pools (random: 57%).

• Localization. SPLASH places the vulnerable statement first in 58% of insecure programs (random: 9%) and identifies the exact changed line in 77% of benchmark reference pairs.

• Practitioner comparison. SPLASH selects secure code more often than a frontier LLM judge (77% vs. 68%) while requiring only local inference rather than per-query API calls. Although the judge localizes more precisely on its sample (70% vs. 54% top-1), SPLASH provides both selection and localization from the same pass.

Contributions. We make the following contributions in this paper:

• Problem characterization. We provide the first study showing that security hallucinations are written confidently and repeated across samples, across 12 generators and 899 tested tasks, establishing that generation uncertainty and static analysis both miss most of them ( §6.1§6.1).

• Method and system. We introduce audit pressure, a training-free, model-agnostic signal grounded in a formal model of competing edits, and build SPLASH, a pipeline that takes generated code from any source and produces per-statement localization and per-pool candidate selection ( §4§4, §3§3).

• Rigorous evaluation. We show that SPLASH achieves consistent gains across benchmarks, temperatures, model sizes, and beats random chance on 16 of 17 CWE types, comparing against static analyzers, a frontier LLM judge, and the generator’s own uncertainty ( §6.2–§6.5§6.2–§6.5). The code and artifacts of SPLASH are publicly available at: https://github.com/Prometheused/SPLASH

References (20)