- Rating
- 3(+1)
- Confidence
- 3
- Informativeness
- 2
- Presentation
- 2
- Soundness
- 2
Read review
Paper summary
The paper introduces an SFT + RL based method to improve LLMs in secure code generation. First, in the SFT stage, the method trains on examples of vulnerability detection and fixing. Then, in the RL stage, secure code generation is trained with PPO, where the reward consists of token-level positive reward for each "secure" token, and sample-level negative reward for each sample that is detected as vulnerable. For calculating these rewards, a larger "teacher" model is employed to detect secure spans and judge vulnerability. Results on secure code generation benchmarks show clear improvements.
Critical strengths
- Important topic.
- Interesting and effective approach to construct an SFT + RL curriculum.
- Promising results on the tested benchmarks and models.
Critical weaknesses
- I have some concerns about the method. It relies on a "teacher" model that is able to detect secure spans in the code and also to judge if the final code snippet is secure or not. I do believe that this works well in the examined settings, which is relatively outdated (more on this in the next point), but I have some doubts over how well this method extrapolates towards the frontier as coding tasks become more complex and harder for any model to judge.
- The finetuned models, used benchmarks, and overall setting is somewhat outdated. Current coding workloads use mostly agentic setups with often larger, or at least more capable, reasoning models as backbones. This research however targets still single-turn and pure LLM-based, tightly scoped coding tasks. It is therefore unclear how relevant this method is to the current coding frontier, and if any components of the method would be useful to improve current models. While I understand that in part (or largely) this is also due to the fact that working on larger/more capable models is prohibitively expensive for academics. However, there are still smaller-scale LLMs that are excellent at agentic coding, which could come at comparable training budgets as the models used in the paper (e.g., smaller models in the latest Qwen reasoning series). Also, even the specific field of secure code generation is already moving further. For instance Wang et al. (2026), uses the more advanced benchmarks of BaxBench for secure coding and LiveCodeBench for functionality testing.
- I also have some concerns about the comparison to SafeCoder. SafeCoder is highly sensitive to the specific set of CWEs that are contained in the training data. As the training data of the presented method and that of SafeCoder differ, I am wondering how much of the resulting differences due to the training data being different. Could you report the CWEval results of both your method and that of SafeCoder reduced only to the CWEs that are contained in the SafeCoder dataset? Or could you examine constructing an extension to SafeCoder's dataset using your dataset and then training with SafeCoder's training method?
- Further, I am a bit surprised, and somewhat sceptical about the strong functionality preservation (even improvement) results. Could you discuss in more detail how this is possible? In my experience, most recent open-weight models are so well trained that it is incredibly hard to not hurt their base capabilities without doing some delicate additional training aimed at preserving these capabilities. Perhaps to this point it would also be important to evaluate the models on some harder tasks, e.g., LiveCodeBench.
- Finally, I have some points about presentation. The paper is in parts hard to follow, because the "teacher" is never well defined or presented.
References
Wang et al. SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization. arXiv 2026.
Questions for authors
See weaknesses.
8 comments
Response to Reviewer ncGv (Part 2 / 5)
W1 & W2 (Continued from Part 1):
A1-A2: We further present two representative case studies.
Case Study 1: Balancing Functionality and Path Security in BaxBench.
We further examine the FileSearch scenario in BaxBench, which requires implementing a file-search API within /data while supporting legitimate subdirectory requests and preventing directory traversal. SRCode successfully balances functional correctness and security by normalizing requested paths and validating their containment within the permitted directory. In contrast, SafeCoder sacrifices functionality for security by rejecting legitimate requests such as search_dir="/songs", while SecCoderX preserves functionality but introduces a security vulnerability by incorrectly using string-prefix matching to validate directory boundaries. The Base model similarly preserves normal search behavior but lacks sufficient path-boundary validation, allowing directory traversal. These results demonstrate that SRCode's advantage lies not merely in imposing stricter security restrictions, but in precisely enforcing security constraints while preserving legitimate functionality.
Case Study 2: Context-Aware Authorization in A.S.E.
We additionally examine the tsinghua_lunary_cve_2024_4146 instance in A.S.E, a repository-level TypeScript code-completion task associated with CWE-639. The task requires completing the masked checkProjectAccess function using repository context that describes an existing organization-level authorization check and indicates the need for a direct account_project lookup. SRCode correctly enforces project-level authorization by verifying the explicit user–project relationship. In contrast, SafeCoder and SecCoderX preserve insecure organization-level checks, allowing users within the same organization to access projects without explicit authorization. The Base model additionally mishandles the SQL query result by converting the returned object directly to a boolean, causing incorrect access decisions. Unlike these implementations, SRCode identifies the security-critical authorization relationship and preserves the intended functionality. This case demonstrates SRCode's ability to incorporate repository-level security semantics rather than relying solely on local input validation or existing implementation patterns.
Together, these case studies provide concrete evidence complementing the quantitative results in R3-Table 1. They demonstrate that SRCode can preserve legitimate functionality while enforcing security constraints, ranging from filesystem boundary validation to repository-level authorization. These findings further support SRCode's generalizability to more challenging and realistic coding tasks.
(2) Evaluation on a newer-generation model.
To further examine the applicability of SRCode to more recent model architectures, we conducted additional experiments using Qwen3.5-9B, a newer-generation model with a parameter scale suitable for controlled training comparisons. We followed the same evaluation protocols as in the original experiments.
R3-Table 2: Performance comparison on Qwen3.5-9B. | Method | CWEval | CWEval | CodeLMSec | CyberSecEval | LiveCodeBench-v6-new | |:---|:---:|:---:|:---:|:---:|:---:| | | FS@1 (C/C++) | FS@1 (Python) | Sec.Rate | Pass.Rate | Pass@1 | | Base | 26.9 | 40.4 | 68.2 | 56.1 | 39.4 | | SafeCoder | 15.4 | 33.8 | 76.7 | 66.4 | 28.6 | | SecCoderX | 28.9 | 42.3 | 72.2 | 62.4 | 34.9 | | SRCode | 32.7 | 44.2 | 79.9 | 67.8 | 36.6 |
SRCode achieves the best performance across all four security-oriented metrics, outperforming SecCoderX by 3.8, 1.9, 7.7, and 5.4 percentage points, respectively. Importantly, SRCode also achieves the highest LiveCodeBench Pass@1 among the security-tuned methods (36.6), narrowing the functionality gap relative to the base model.
However, we observe that security-oriented fine-tuning on general-purpose models leads to a decline in general coding capabilities, unlike the improvements observed with code-specialized models. We discuss this distinction and its implications in greater detail in Part 4.
These findings demonstrate that SRCode remains effective on a newer-generation model rather than relying exclusively on the original Qwen2.5-Coder initialization.
We will incorporate R3-Tables 1–2 into Section 4.2 and Section 4.5, respectively, and provide the corresponding benchmark configurations and model-specific training settings in Appendix C.
Response to Reviewer ncGv (Part 3 / 5)
W3: Fair Comparison with SafeCoder under Matched Training Data.
Concern: SafeCoder is sensitive to the CWE distribution of its training data. Differences between SRCode and SafeCoder may therefore reflect differences in training data rather than the effectiveness of the proposed method.
A3: We thank the reviewer for this important observation. To isolate the influence of training data, we conducted an additional data-matched SafeCoder experiment. Following your suggestion, we incorporated PrimeVul+ into SafeCoder's original training data, following its data construction and training procedure, trained SafeCoder using the same base model as in our original experiments, and evaluated the resulting model on CWEval and LiveCodeBench-v6-new.
R3-Table 3: Comparison with SafeCoder augmented with PrimeVul+. | Model | CWEval | CWEval | LiveCodeBench-v6-new | |:---|:---:|:---:|:---:| | | FS@1 (C/C++) | FS@1 (Python) | Pass@1 | | Base | 28.9 | 45.0 | 18.9 | | SafeCoder | 19.2 | 43.5 | 14.9 | | SafeCoder (origin & PrimeVul+) | 26.9 | 43.5 | 13.7 | | SRCode | 38.5 | 54.2 | 21.1 |
As shown in R3-Table 3, augmenting SafeCoder's original training data with PrimeVul+ improves its CWEval FS@1 (C/C++) from 19.2 to 26.9, confirming that the training data distribution can meaningfully influence its security performance. However, SRCode still substantially outperforms SafeCoder (origin & PrimeVul+), achieving 38.5 versus 26.9 on CWEval (C/C++) and 54.2 versus 43.5 on CWEval (Python), corresponding to improvements of 11.6 and 10.7 percentage points, respectively.
Moreover, SafeCoder (origin & PrimeVul+) achieves 13.7 Pass@1 on LiveCodeBench-v6-new, compared with 21.1 for SRCode. This indicates that augmenting SafeCoder's original training data with PrimeVul+ does not reproduce SRCode's improvements in either secure code generation or general coding functionality.
These results directly address the concern about training-data differences. While data composition affects baseline performance, the remaining gap under matched training data provides stronger evidence that SRCode's SFT–RL curriculum and token-level reward optimization contribute beyond the choice of training dataset.
We will incorporate this data-matched comparison into Section 4.2 and Appendix I, explicitly documenting the SafeCoder data construction procedure, matched base model, and training configurations to improve the fairness and reproducibility of the comparison.
Response to Reviewer ncGv (Part 1 / 5)
We sincerely thank the reviewer for the thoughtful and constructive feedback. We are encouraged by your positive recognition of the importance of our research topic, our SFT–RL methodological design, and the promising empirical results.
We hope these clarifications and new results will address your remaining concerns and we respectfully ask if you're comfortable to reconsider the rating in light of our efforts and dedication. Below, we provide detailed responses to all the comments:
W1 & W2: Generalization to More Challenging Coding Tasks and Newer Models.
A1–A2: We appreciate the reviewer for highlighting the importance of evaluating SRCode beyond its original experimental setting. To address these concerns, we conducted two additional sets of experiments: (i) evaluations on more challenging security and coding benchmarks, and (ii) experiments with a newer-generation Qwen model.
(1) Evaluation on more challenging security and coding benchmarks.
We additionally evaluated SRCode on BaxBench and A.S.E. to assess security-oriented coding performance, alongside LiveCodeBench-v6-new to evaluate general code generation capabilities.
As shown in R3-Table 1, SRCode consistently achieves the best performance across all five metrics. On BaxBench, SRCode obtains a Correct & Secure score of 23.4, outperforming SecCoderX by 6.6 percentage points. On A.S.E., SRCode achieves 30.6 in Security and 45.6 in Overall, exceeding the strongest baselines by 7.2 and 8.3 points, respectively. Meanwhile, its LiveCodeBench-v6-new Pass@1 reaches 21.1, compared with 18.9 for the base model and 20.6 for SecCoderX.
These results are encouraging because more challenging coding tasks require the model to balance functional correctness with security constraints across multiple implementation decisions. Although TLR assigns localized rewards during training, its benefits extend beyond the original benchmarks, suggesting that fine-grained security reinforcement can improve coding behavior in more demanding evaluation settings.