arXiv:2608.14303cs.LG2026-08

用影响函数检测代码生成提示中的恶意批量,无需事先知道攻击类型。

Detecting Contaminated Code-Generation Prompt Batches via Influence Functions

论文配图:Detecting Contaminated Code-Generation Prompt Batches via Influence Functions
图 1 · 摘自论文原文
  • 通过参数空间影响度量判断提示批次是否异常
  • 在3个3B~7B模型上达0.98的AUROC,误报率可控
  • 适合安全团队快速筛查可疑提示批量

大型语言模型在代码生成中日益普及,但仍易受诱导生成不安全代码的提示影响。现有防御方法依赖预设威胁模型或已知漏洞模式,难以应对新型攻击。本文提出CodeSIFT,一种无威胁模型依赖的检测方法,利用影响函数识别引发模型异常行为的提示批次。该方法不检测具体漏洞,而是测量生成代码对模型参数的影响,并通过统计检验判断候选提示集是否偏离良性参考分布。为评估效果,我们构建了两个涵盖多种漏洞的基准数据集。在三个开源代码LLM(参数量3B至7B)上测试,CodeSIFT在中高注入率下达到最高0.98的AUROC,同时保持良好校准的假阳性率,显著优于静态分析基线。结果表明,基于影响函数的检测是无需先验攻击知识识别恶意代码生成提示的有前景方向。

原文摘要 · Abstract (English)

Large language models (LLMs) are increasingly used for code generation, yet they remain vulnerable to prompts that elicit insecure implementations. Existing defenses typically rely on predefined threat models or known vulnerability patterns, limiting their effectiveness against novel attacks. We propose CodeSIFT, a threat-model-agnostic detection method that leverages influence functions to identify batches of prompts that induce anomalous model behavior. Rather than detecting specific vulnerabilities, CodeSIFT measures the parameter-space influence of generated code and uses a statistical test to determine whether a candidate prompt set deviates from a benign reference distribution. To evaluate our approach, we introduce two benchmark datasets covering a variety of vulnerabilities. We evaluate CodeSIFT on three open-weight code LLMs ranging from 3B to 7B parameters, achieving AUROC scores of up to 0.98 at moderate-to-high injection rates, while maintaining well-calibrated false positive rates and substantially outperforming static analysis baselines. These results suggest that influence-function-based detection is a promising direction for identifying malicious code-generation prompts without requiring prior knowledge of the underlying attack class.

代码安全影响函数提示检测LLM防御

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。