Learning to Generate Secure Code via Token-Level Rewards

Jiazheng Quan, Xiaodong Li, Bin Wang, Guo An, Like Liu +3 more
2/26/2026
cs.CRcs.AIcs.SE
rl

No confident code implementation found for this paper.

Abstract

Large language models (LLMs) have demonstrated strong capabilities in code generation, yet they remain prone to producing security vulnerabilities. Existing approaches commonly suffer from two key limitations: the scarcity of high-quality security data and coarse-grained reinforcement learning reward signals.

Show full abstract

To address these challenges, we propose Vul2Safe, a new secure code generation framework that leverages LLM self-reflection to construct high-confidence repair pairs from real-world vulnerabilities, and further generates diverse implicit prompts to build the PrimeVul+ dataset. Meanwhile, we introduce SRCode, a novel training framework that pioneers the use of token-level rewards in reinforcement learning for code security, which enables the model to continuously attend to and reinforce critical fine-grained security patterns during training. Compared with traditional instance-level reward schemes, our approach allows for more precise optimization of local security implementations. Extensive experiments show that PrimeVul+ and SRCode substantially reduce security vulnerabilities in generated code while improving overall code quality across multiple benchmarks.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{quan2026learning,
  title  = {Learning to Generate Secure Code via Token-Level Rewards},
  author = {Jiazheng Quan and Xiaodong Li and Bin Wang and Guo An and Like Liu and Degen Huang and Lin Liu and Chengbin Hou},
  year   = {2026},
  eprint = {2602.23407},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2602.23407v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2602.23407.svg)](https://codeofpaper.com/paper/2602.23407)

Discussion