A Mixture of Linear Corrections Generates Secure Code
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) have become proficient at sophisticated code-generation tasks, yet remain ineffective at reliably detecting or avoiding code vulnerabilities. Does this deficiency stem from insufficient learning about code vulnerabilities, or is it merely a result of ineffective prompting? Using representation engineering techniques, we investigate whether LLMs internally encode the concepts necessary to identify code vulnerabilities. We find that current LLMs encode precise internal representations that distinguish vulnerable from secure code--achieving greater accuracy than standard prompting approaches. Leveraging these vulnerability-sensitive representations, we develop an inference-time steering technique that subtly modulates the model's token-generation probabilities through a mixture of corrections (MoC). Our method effectively guides LLMs to produce less vulnerable code without compromising functionality, demonstrating a practical approach to controlled vulnerability management in generated code. Notably, MoC enhances the security ratio of Qwen2.5-Coder-7B by 8.9%, while simultaneously improving functionality on HumanEval pass@1 by 2.1%.
Key facts. Cited by 4 papers in the map (data through 14 Oct 2026). Builds on 33 of its 42 references that are in the map. First posted on arXiv 13 Jul 2025.
Builds on
33 of 42 references.
References · 33
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2022Solving Quantitative Reasoning Problems with Language Modelscited by 1,392
- 2016Understanding intermediate layers using linear classifier probescited by 1,353
- 2023Representation Engineering: A Top-Down Approach to AI Transparencycited by 1,336
- 2024Qwen2.5-Coder Technical Reportcited by 1,203
- 2023Steering Llama 2 via Contrastive Activation Additioncited by 1,085
- 2023The Internal State of an LLM Knows When It's Lyingcited by 659
- 2024A Survey on Large Language Models for Code Generationcited by 658
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
- 2023CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-Xcited by 300
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
21 more
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2024Vulnerability Detection with Code Language Models: How Far Are We?cited by 139
- 2024Personalized Steering of Large Language Models: Versatile Steering Vectors Through Bi-directional Preference Optimizationcited by 118
- 2023LLMs Cannot Reliably Identify and Reason About Security Vulnerabilities (Yet?): A Comprehensive Evaluation, Framework, and Benchmarkscited by 97
- 2024Adaptive Activation Steering: A Tuning-Free LLM Truthfulness Improvement Method for Diverse Hallucinations Categoriescited by 77
- 2024Instruction Tuning for Secure Code Generationcited by 68
- 2024Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGcited by 68
- 2023Understanding the Effectiveness of Large Language Models in Detecting Security Vulnerabilitiescited by 59
- 2024LLM4Vuln: A Unified Evaluation Framework for Decoupling and Enhancing LLMs' Vulnerability Reasoningcited by 59
- 2024Controllable Text Generation for Large Language Models: A Surveycited by 57
- 2024Large Language Model for Vulnerability Detection: Emerging Results and Future Directionscited by 45
- 2023ChatGPT for Vulnerability Detection, Classification, and Repair: How Far Are We?cited by 44
- 2025Taxonomy, Opportunities, and Challenges of Representation Engineering for Large Language Modelscited by 34
- 2024Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuningcited by 30
- 2024ProSec: Fortifying Code LLMs with Proactive Security Alignmentcited by 25
- 2024Learning Code Preference via Synthetic Evolutioncited by 19
- 2024Towards Inference-time Category-wise Safety Steering for Large Language Modelscited by 18
- 2024Security Vulnerability Detection with Multitask Self-Instructed Fine-Tuning of Large Language Modelscited by 14
- 2024DocCGen: Document-based Controlled Code Generationcited by 11
- 2024INDICT: Code Generation with Internal Dialogues of Critiques for Both Security and Helpfulnesscited by 8
- 2024APILOT: Navigating Large Language Models to Generate Secure Code by Sidestepping Outdated API Pitfallscited by 3
Built on by
Citing papers per year: 2025: 2; 2026: 2.
4 papers.
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 15
- 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Modelcited by 6
- 2026On the Robustness of LLMs' Internal Representation of Code Correctnesscited by 1
- 2025Microsaccade-Inspired Probing: Positional Encoding Perturbations Reveal LLM Misbehaviourscited by 0
- 2026On the Robustness of LLMs' Internal Representation of Code Correctness8 Aug 2026
- 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model7 Feb 2026
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligence23 Nov 2025
- 2025Microsaccade-Inspired Probing: Positional Encoding Perturbations Reveal LLM Misbehaviours1 Oct 2025
Similar, not cited
Close in wording, no citation either way
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms
- 2026Surgical Repair of Insecure Code Generation in LLMs
- 2026Minimal Prompt Perturbations Lead to Code Vulnerabilities: Prompt Fragility and Hidden-State Signals in Coding LLMs
- 2025Explicit Vulnerability Generation with LLMs: An Investigation Beyond Adversarial Attacks
- 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision
- 2026Enhancing Reliability in LLM-Based Secure Code Generation
- 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
- 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios