SecPI: 보안 추론 모델을 활용한 안전한 코드 생성: 보안 추론 내부화
SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization
추론 언어 모델(RLM)은 프로그래밍 분야에서 점점 더 많이 활용되고 있습니다. 하지만 최첨단 RLM조차도 생성된 코드에 심각한 보안 취약점을 자주 발생시킵니다. 안전한 코드 생성을 위한 기존의 훈련 기반 방법은 RLM에 직접 적용할 수 없는 중요한 한계를 가지고 있습니다. 이러한 방법들은 비용이 많이 들고 수동으로 구성된 보안 데이터 세트에 의존하며, 이는 제한된 범위의 취약점만 다룹니다. 추론 단계에서, 일반적인 보안 알림은 기능적 정확성을 저하시키는 동시에 피상적인, 즉흥적인 취약점 분석만 유발합니다. 이러한 문제점을 해결하기 위해, 우리는 SecPI라는 파인튜닝 파이프라인을 제안합니다. SecPI는 RLM에게 구조화된 보안 추론을 학습시켜, 추론 시 보안 관련 지침 없이도 기본적으로 안전한 코드를 생성하도록 합니다. SecPI는 LLM 기반 분류기를 사용하여 기존의 범용 코딩 데이터 세트에서 보안 관련 작업을 필터링하고, 구조화된 프롬프트를 통해 체계적으로 관련 CWE(Common Weakness Enumeration)와 해결 방법을 나열하여 교사 모델의 안내를 받아 고품질의 보안 추론 기록을 생성합니다. 또한, 대상 모델은 보안 관련 프롬프트가 없는 입력과 교사 모델의 추론 기록 쌍으로 파인튜닝됩니다. 그 결과, 모델은 명시적인 지시에 대한 반응이 아닌, 자율적으로 보안에 대해 추론하는 방법을 학습합니다. 최첨단 오픈 가중치 추론 모델을 사용한 광범위한 평가를 통해, 우리의 접근 방식의 효과가 검증되었습니다. 예를 들어, SecPI는 QwQ 32B의 CWEval에서의 기능적으로 정확하고 안전한 코드 생성 비율을 48.2%에서 62.2% (+14.0 포인트)로, BaxBench에서의 비율을 18.2%에서 22.0%로 향상시켰습니다. 또한, 추가적인 조사를 통해 훈련된 취약점 외에도 다양한 CWE와 다양한 프로그래밍 언어에 대한 강력한 일반화 능력을 확인했습니다. QwQ 32B는 메모리 안전과 관련된 CWE로만 훈련되었음에도 불구하고, 보류된 메모리 안전 CWE에 대해 9.9% 더 자주 정확하고 안전한 코드를 생성합니다.
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.
No Analysis Report Yet
This paper hasn't been analyzed by Gemini yet.
Log in to request an AI analysis.