Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model
Large language models (LLMs) are increasingly used in software development, yet their tendency to generate insecure code remains a major barrier to real-world deployment. Existing secure code alignment methods often suffer from a functionality--security paradox, improving security at the cost of substantial utility degradation. We propose SecCoderX, an online reinforcement learning framework for functionality-preserving secure code generation. SecCoderX first bridges vulnerability detection and secure code generation by repurposing mature detection resources in two ways: (i) synthesizing diverse, reality-grounded vulnerability-inducing coding tasks for online RL rollouts, and (ii) training a reasoning-based vulnerability reward model that provides scalable and reliable security supervision. Together, these components are unified in an online RL loop to align code LLMs to generate secure and functional code. Extensive experiments demonstrate that SecCoderX achieves state-of-the-art performance, improving Effective Safety Rate (ESR) by approximately 10% over unaligned models, whereas prior methods often degrade ESR by 14-54%. We release our code, dataset and model checkpoints at https://github.com/AndrewWTY/SecCoderX.
698c9b1b6c5152984e4f3c8c
Tianyi Wu
698c9b1b6c5152984e4f3c8d
Mingzhe Du
claimed_verified
2026-02-17T15:50:46.234Z
61711f02e0b1ddb56eb9b526
/avatars/3e2fdf774f5bc1f73b450486d6da42d4.svg
Mingzhe Du
Elfsong
user
Elfsong
698c9b1b6c5152984e4f3c8e
Yue Liu
698c9b1b6c5152984e4f3c8f
Chengran Yang
698c9b1b6c5152984e4f3c90
Terry Yue Zhuo
698c9b1b6c5152984e4f3c91
Jiaheng Zhang
698c9b1b6c5152984e4f3c92
See-Kiong Ng
Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model
Large language models (LLMs) are increasingly used in software development, yet their tendency to generate insecure code remains a major barrier to real-world deployment. Existing secure code alignment methods often suffer from a functionality--security paradox, improving security at the cost of substantial utility degradation. We propose SecCoderX, an online reinforcement learning framework for functionality-preserving secure code generation. SecCoderX first bridges vulnerability detection and secure code generation by repurposing mature detection resources in two ways: (i) synthesizing diverse, reality-grounded vulnerability-inducing coding tasks for online RL rollouts, and (ii) training a reasoning-based vulnerability reward model that provides scalable and reliable security supervision. Together, these components are unified in an online RL loop to align code LLMs to generate secure and functional code. Extensive experiments demonstrate that SecCoderX achieves state-of-the-art performance, improving Effective Safety Rate (ESR) by approximately 10% over unaligned models, whereas prior methods often degrade ESR by 14-54%. We release our code, dataset and model checkpoints at https://github.com/AndrewWTY/SecCoderX.
SecCoderX uses online reinforcement learning to align large language models for secure code generation while preserving functionality, addressing the functionality-security trade-off through vulnerability detection integration and reward modeling.
large language models secure code generation online reinforcement learning vulnerability detection reward model functionality-preserving code alignment security supervision