mlsanityData to 14 Oct 2026

Teaching an Old LLM Secure Coding: Localized Preference Optimization on Distilled Preferences

arXiv 2506.00419 ↗First posted 31 May 2025cs.CR cs.SEcited by 10

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

  1. 2024ProSec: Fortifying Code LLMs with Proactive Security Alignment19 Nov

Other references · 32

  1. 2022Training language models to follow instructions with human feedbackcited by 15,971
  2. 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,380
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  4. 2023Direct Preference Optimization: Your Language Model is Secretly a Reward Modelcited by 8,065
  5. 2021Finetuned Language Models Are Zero-Shot Learnerscited by 3,780
  6. 2021Program Synthesis with Large Language Modelscited by 3,637
  7. 2023SWE-bench: Can Language Models Resolve Real-World GitHub Issues?cited by 3,373
  8. 2023Code Llama: Open Foundation Models for Codecited by 2,139
  9. 2024SimPO: Simple Preference Optimization with a Reference-Free Rewardcited by 963
  10. 2021Measuring Coding Challenge Competence With APPScited by 902
  11. 2023StarCoder: may the source be with you!cited by 799
  12. 2024Phi-4 Technical Reportcited by 711
20 more
  1. 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
  2. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
  3. 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 367
  4. 2024Deliberative Alignment: Reasoning Enables Safer Language Modelscited by 308
  5. 2022Multi-lingual Evaluation of Code Generation Modelscited by 159
  6. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
  7. 2021CVEfixes: Automated Collection of Vulnerabilities and Their Fixes from Open-Source Softwarecited by 91
  8. 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 91
  9. 2023How Secure is Code Generated by ChatGPT?cited by 81
  10. 2024Instruction Tuning for Secure Code Generationcited by 68
  11. 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 62
  12. 2024SelfCodeAlign: Self-Alignment for Code Generationcited by 62
  13. 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 59
  14. 2023WaveCoder: Widespread And Versatile Enhancement For Code Large Language Models By Instruction Tuningcited by 42
  15. 2024Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuningcited by 30
  16. 2024Learning Code Preference via Synthetic Evolutioncited by 19
  17. 2024Code Needs Comments: Enhancing Code LLMs with Comment Augmentationcited by 16
  18. 2024HexaCoder: Secure Code Generation via Oracle-Guided Synthetic Training Datacited by 16
  19. 2024SecCoder: Towards Generalizable and Robust Secure Code Generationcited by 14
  20. 2024DolphCoder: Echo-Locating Code Large Language Models with Diverse and Multi-Objective Instruction Tuningcited by 11

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 3; 2026: 7.

10 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization
  2. 2026Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-based Code Generation ↗
  3. 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
  4. 2026Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model
  5. 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
  6. 2024LLM-Powered Code Vulnerability Repair with Reinforcement Learning and Semantic Reward
  7. 2026Enhancing Reliability in LLM-Based Secure Code Generation
  8. 2026Minimal Prompt Perturbations Lead to Code Vulnerabilities: Prompt Fragility and Hidden-State Signals in Coding LLMs