arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2606.19235cs.CR
收藏

CodeSentinel:代码上下文中针对间接提示注入的三层防御

CodeSentinel: A Three-Layer Defense Against Indirect Prompt Injection in Code Contexts

National Yang Ming Chiao Tung University(国立阳明交通大学);Hon Hai Research Institute(鸿海研究院)

Po-Han Cheng, Chia-Mu Yu, Ying-Dar Lin, Yu-Sung Wu, Wei-Bin Lee

AI总结:

针对代码大语言模型在检索外部代码时面临的间接提示注入攻击,提出CodeSentinel三层推理时净化器,结合语法引导预过滤、CST引导动态Min-K%评分和节点扰动分析,实现0.80节点级F1,优于现有方法。

摘要:

代码大语言模型越来越多地从仓库、文档、问题线程和编码代理环境中检索外部代码上下文,这创建了一个间接提示注入面,攻击者可以在注释、字符串、标识符或诱饵代码中隐藏指令。我们提出了CodeSentinel,一个三层推理时净化器。它使用Tree-sitter提取高风险模型面对CST节点,然后结合语法引导预过滤、CST引导动态Min-K%评分和节点扰动分析来检测对抗性和自然外观的语义触发器。检测到的节点在被下游代码LLM处理之前被移除或中和。在六个最近的攻击家族中,CodeSentinel实现了0.80的平均节点级F1,优于CodeGarrison、DePA和KillBadCode。

英文摘要:

Code large language models increasingly retrieve external code context from repositories, documentation, issue threads, and coding-agent environments, creating an indirect prompt-injection surface where attackers hide instructions in comments, strings, identifiers, or decoy code. We propose CodeSentinel, a three-layer inference-time sanitizer. It uses Tree-sitter to extract high-risk model-facing CST nodes, then combines syntax-guided pre-filtering, CST-guided Dynamic Min-K\% scoring, and node perturbation analysis to detect adversarial and natural-looking semantic triggers. Detected nodes are removed or neutralized before reaching the downstream Code LLM. Across six recent attack families, \CodeSentinel achieves 0.80 average node-level F1, outperforming CodeGarrison, DePA, and KillBadCode.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑