Teaching an Old LLM Secure Coding: Localized Preference Optimization on Distilled Preferences
Mohammad Saqib Hasan, Saikat Chakraborty, Santu Karmaker, Niranjan Balasubramanian

TL;DR
This paper introduces a systematic approach to improve secure code generation in large language models by distilling a preference dataset and developing a localized preference optimization algorithm that focuses on security-related code regions.
Contribution
The paper presents a novel method for distilling security-focused preferences from LLMs and a localized preference optimization algorithm that enhances secure code generation.
Findings
Significant reduction in insecure code generation.
Improved overall code quality.
Effective handling of localized security issues.
Abstract
LLM generated code often contains security issues. We address two key challenges in improving secure code generation. First, obtaining high quality training data covering a broad set of security issues is critical. To address this, we introduce a method for distilling a preference dataset of insecure and secure code pairs from frontier LLMs, along with a security reasoning that explains the issues and the fix. The key idea here is to make use of security knowledge sources to devise a systematic prompting strategy that ensures broad coverage. Second, aligning models to secure code requires focusing on localized regions of code. Direct preference optimization methods, like SimPO, are not designed to handle these localized differences and turn out to be ineffective. We address this with a new localized preference optimization algorithm that masks the security related tokens in both the…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
Taxonomy
TopicsIntellectual Property Rights and Media · Dispute Resolution and Class Actions
