Teaching an Old LLM Secure Coding: Localized Preference Optimization on Distilled Preferences
On the map: LLM alignment / RLHF / preference optimisation → Safety alignment and jailbreak attacks
Abstract (arXiv)
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 winning (secure) and losing (insecure) responses. To prevent loss in code quality, we also add a regularizer. Evaluations show that both training on our dataset, DiSCo, and the new preference optimization algorithm, LPO, yield substantial reductions in code insecurity while also improving overall code quality. Code and dataset are available at https://github.com/StonyBrookNLP/disco-lpo.
Key facts. Cited by 10 papers in the map (data through 14 Oct 2026). Placed in Safety alignment and jailbreak attacks, one of 10 directions in LLM alignment / RLHF / preference optimisation. Builds on 33 of its 51 references that are in the map. First posted on arXiv 31 May 2025.
Builds on
33 of 51 references.
Closest ancestors · 1
Same direction, newest first
Other references · 32
- 2022Training language models to follow instructions with human feedbackcited by 15,971
- 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,380
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Direct Preference Optimization: Your Language Model is Secretly a Reward Modelcited by 8,065
- 2021Finetuned Language Models Are Zero-Shot Learnerscited by 3,780
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2023SWE-bench: Can Language Models Resolve Real-World GitHub Issues?cited by 3,373
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2024SimPO: Simple Preference Optimization with a Reference-Free Rewardcited by 963
- 2021Measuring Coding Challenge Competence With APPScited by 902
- 2023StarCoder: may the source be with you!cited by 799
- 2024Phi-4 Technical Reportcited by 711
20 more
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
- 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 367
- 2024Deliberative Alignment: Reasoning Enables Safer Language Modelscited by 308
- 2022Multi-lingual Evaluation of Code Generation Modelscited by 159
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2021CVEfixes: Automated Collection of Vulnerabilities and Their Fixes from Open-Source Softwarecited by 91
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 91
- 2023How Secure is Code Generated by ChatGPT?cited by 81
- 2024Instruction Tuning for Secure Code Generationcited by 68
- 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 62
- 2024SelfCodeAlign: Self-Alignment for Code Generationcited by 62
- 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 59
- 2023WaveCoder: Widespread And Versatile Enhancement For Code Large Language Models By Instruction Tuningcited by 42
- 2024Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuningcited by 30
- 2024Learning Code Preference via Synthetic Evolutioncited by 19
- 2024Code Needs Comments: Enhancing Code LLMs with Comment Augmentationcited by 16
- 2024HexaCoder: Secure Code Generation via Oracle-Guided Synthetic Training Datacited by 16
- 2024SecCoder: Towards Generalizable and Robust Secure Code Generationcited by 14
- 2024DolphCoder: Echo-Locating Code Large Language Models with Diverse and Multi-Objective Instruction Tuningcited by 11
Built on by
Citing papers per year: 2025: 3; 2026: 7.
10 papers.
- 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic Systemcited by 15
- 2025Data and Context Matter: Towards Generalizing AI-based Software Vulnerability Detectioncited by 3
- 2026Learning to Generate Secure Code via Token-Level Rewardscited by 2
- 2025ProST: Progressive Sub-task Training for Pareto-Optimal Multi-agent Systems Using Small Language Modelscited by 1
- 2026Autoregressive, Yet Revisable: In Decoding Revision for Secure Code Generationcited by 1
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalizationcited by 1
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versionscited by 1
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026Functional and Secure Code Generation with Task Vectorscited by 0
- 2026MACGen: Toward Functionally Correct and Secure Code Generation via Multi-Agent Collaborationcited by 0
- 2026MACGen: Toward Functionally Correct and Secure Code Generation via Multi-Agent Collaboration26 Aug 2026
- 2026Functional and Secure Code Generation with Task Vectors8 Jul 2026
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versions7 May 2026
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization4 Apr 2026
- 2026Learning to Generate Secure Code via Token-Level Rewards26 Feb 2026
- 2026Autoregressive, Yet Revisable: In Decoding Revision for Secure Code Generation1 Feb 2026
- 2025A Comprehensive Survey on Benchmarks and Solutions in Software Engineering of LLM-Empowered Agentic System10 Oct 2025
- 2025ProST: Progressive Sub-task Training for Pareto-Optimal Multi-agent Systems Using Small Language Models2 Sep 2025
- 2025Data and Context Matter: Towards Generalizing AI-based Software Vulnerability Detection14 Aug 2025
Similar, not cited
Close in wording, no citation either way
- 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization
- 2026Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-based Code Generation ↗
- 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
- 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model
- 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
- 2024LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Reward
- 2026Enhancing Reliability in LLM-Based Secure Code Generation
- 2026Minimal Prompt Perturbations Lead to Code Vulnerabilities: Prompt Fragility and Hidden-State Signals in Coding LLMs