Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generation

Xiaoyun Xu, Lichao Wu, Jona te Lintelo, Siyu Zhang, Keke Gai +1 more
6/15/2026
cs.CRcs.AI

No confident code implementation found for this paper.

Abstract

Large language models are pretrained on extensive software and security corpora, yet they frequently generate functionally correct code containing well-known vulnerabilities. Existing defenses commonly treat this behavior as a knowledge deficit, addressing it through model-specific fine-tuning or retrieval from large collections of vulnerability code examples.

Show full abstract

We argue that insecure generation can arise from a failure to activate task-relevant security knowledge, rather than from knowledge absence alone. We present BRACE, an inference-time, training-free security harness for risk-conditioned activation of security knowledge in black-box code generation. Given only a coding task, BRACE first utilizes an LLM (as a security expert) to identify task-relevant security risks. The predicted risk identifiers are validated against a lightweight canonical catalog and converted into concise, task-specific risk cues. BRACE then supplies these cues to the target code model, prompting it to apply its own secure-coding knowledge while satisfying the original functional requirements. The framework requires no target-model fine-tuning, parameter access, hidden states, mutable logits, learned retriever, or coding-example knowledge base. We evaluate BRACE on six open-weight models and six frontier commercial models with four benchmarks (CyberNative, HumanEval, CWEval, BaxBench), measuring functional correctness, security, joint functionality-security, and project-level generation. BRACE raises the average Safe Code Rate from 33.9% under Secure Prompt to 91.2% on CyberNative. It also improves CWEval Func-Sec performance from 49.7% to 69.6%. Mechanism-oriented ablations further show that the gains depend on selecting task-relevant risks.

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{xu2026activating,
  title  = {Activating Latent Security Knowledge through LLM-Guided Risk Analysis for Secure Code Generation},
  author = {Xiaoyun Xu and Lichao Wu and Jona te Lintelo and Siyu Zhang and Keke Gai and Stjepan Picek},
  year   = {2026},
  eprint = {2606.16244},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2606.16244v2}
}

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/2606.16244.svg)](https://codeofpaper.com/paper/2606.16244)

Discussion