paper-with-me

홈 › Papers

SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization

2026-04-04 · Hao Wang, Niels Mündler, Mark Vero, Jingxuan He, Dawn Song, Martin Vechev arxiv

Reasoning language models (RLMs) are increasingly used in programming. Yet, even state-of-the-art RLMs frequently introduce critical security vulnerabilities in generated code. Prior training-based approaches for secure code generation face a critical limitation that prevents their direct application to RLMs: they rely on costly, manually curated security datasets covering only a limited set of vulnerabilities. At the inference level, generic security reminders consistently degrade functional correctness while triggering only shallow ad-hoc vulnerability analysis. To address these problems, we present SecPI, a fine-tuning pipeline that teaches RLMs to internalize structured security reasoning, producing secure code by default without any security instructions at inference time. SecPI filters existing general-purpose coding datasets for security-relevant tasks using an LLM-based classifier, generates high-quality security reasoning traces with a teacher model guided by a structured prompt that systematically enumerates relevant CWEs and mitigations, and fine-tunes the target model on pairs of inputs with no security prompt and teacher reasoning traces -- as a result, the model learns to reason about security autonomously rather than in response to explicit instructions. An extensive evaluation on security benchmarks with state-of-the-art open-weight reasoning models validates the effectiveness of our approach. For instance, SecPI improves the percentage of functionally correct and secure generations for QwQ 32B from 48.2% to 62.2% (+14.0 points) on CWEval and from 18.2% to 22.0% on BaxBench. Further investigation also reveals strong cross-CWE and cross-language generalization beyond training vulnerabilities. Even when trained only on injection-related CWEs, QwQ 32B generates correct and secure code 9.9% more frequently on held-out memory-safety CWEs.

📄 PDF Abstract BibTeX arXiv:2604.03587

Code (0)

등록된 구현이 없습니다.

Tasks

Code Generation

Similar Papers 제목 키워드 기반

Secure Code Generation via Online Reinforcement Learning with Vulnerability Reward Model

2026-02-07 · Tianyi Wu, Mingzhe Du, Yue Liu, Chengran Yang 외 arxiv

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 suff…

Vulnerability DetectionReinforcement LearningCode Generation

SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward

2026-06-23 · Rupam Patir, Keyan Guo, Haipeng Cai, Hongxin Hu arxiv

The increasing use of AI systems for code generation raises a central security question: what can today's models and coding agents actually do to produce secure code, where do they still fail, and what would move the fie…

Reinforcement LearningCode Generation

Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices

2025-10-08 · Rupam Patir, Keyan Guo, Haipeng Cai, Hongxin Hu arxiv

The code generation capabilities of Large Language Models (LLMs) have transformed the field of software development. However, this advancement also presents significant security challenges, as LLM-generated code often co…

Code Generation

Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy Optimization

2025-09-12 · Lei Yu, Jingyuan Zhang, Xin Wang, Jiajia Ma 외 arxiv

Smart contracts automate the management of high-value assets, where vulnerabilities can lead to catastrophic financial losses. This challenge is amplified in Large Language Models (LLMs) by two interconnected failures: t…

Reinforcement Learning

A.S.E: A Repository-Level Benchmark for Evaluating Security in AI-Generated Code

2025-08-25 · Keke Lian, Bin Wang, Lei Zhang, Libo Chen 외 arxiv

The increasing adoption of large language models (LLMs) in software engineering necessitates rigorous security evaluation of their generated code. However, existing benchmarks often lack relevance to real-world AI-assist…

Code Generation