A Mixture of Linear Corrections Generates Secure Code

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Yu, Weichen, Mangal, Ravi, Zhuo, Terry, Fredrikson, Matt, Pasareanu, Corina S.
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866918090680303616
author Yu, Weichen
Mangal, Ravi
Zhuo, Terry
Fredrikson, Matt
Pasareanu, Corina S.
author_facet Yu, Weichen
Mangal, Ravi
Zhuo, Terry
Fredrikson, Matt
Pasareanu, Corina S.
contents 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\%.
format Preprint
id arxiv_https___arxiv_org_abs_2507_09508
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle A Mixture of Linear Corrections Generates Secure Code
Yu, Weichen
Mangal, Ravi
Zhuo, Terry
Fredrikson, Matt
Pasareanu, Corina S.
Cryptography and Security
Artificial Intelligence
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\%.
title A Mixture of Linear Corrections Generates Secure Code
topic Cryptography and Security
Artificial Intelligence
url https://arxiv.org/abs/2507.09508