Words Speak Louder Than Code: Investigating Cognitive Heuristics in LLM-Based Code Vulnerability Detection

LLM HDFE AI Systems and Hardware PVDAR
2026年06月29日
研究人员与实践者正日益将大语言模型(LLMs)应用于自动化漏洞检测。近期研究表明,LLMs 同样容易受到那些影响人类判断的认知启发式(cognitive heuristics)的干扰。然而,尚无研究探讨这些启发式是否会影响模型对代码漏洞的判定。本文首次系统性地探究了认知启发式在基于 LLM 的代码漏洞检测中的作用机制。我们构建了一个受控实验框架:该框架保持待检代码本身不变,仅通过调整其上下文环境,分别触发三种典型认知启发式——通过作者归属信息诱发“光环效应”(halo effect),通过任务目标与后果描述诱发“框架效应”(framing effect),以及通过前置分析结果诱发“锚定效应”(anchoring effect)。在此框架下,我们针对八种主流大语言模型,在三种编程语言上开展评估,并同步进行量化统计分析与细粒度的代码级分析。结果表明,所有被测模型均不同程度地受到上述三种启发式的影响。跨模型平均易感性以框架效应最高(33.2%),其次为锚定效应(23.5%),光环效应最低(18.4%)。代码级分析进一步揭示:需依赖语义推理才能识别的漏洞,比仅凭模式匹配即可发现的漏洞更易受认知启发式干扰;此外,模型常因所处认知条件不同而改变判断结论(例如从“安全”转为“存在漏洞”),却未能准确定位真正的漏洞所在。为凸显其实际危害性,我们还设计并验证了一种黑盒式认知攻击原型:该攻击可在不访问模型内部参数的前提下,成功抑制高达 97% 的先前已检出漏洞。上述发现表明,认知易感性是当前基于大语言模型的漏洞检测方法中一种稳定存在且可被恶意利用的固有缺陷。
Researchers and practitioners increasingly apply Large Language Models (LLMs) for automated vulnerability detection. Recent work has shown that LLMs are susceptible to the same cognitive heuristics that bias human judgment. Yet, no work has investigated whether these heuristics affect a model's assessment of code vulnerabilities. In this paper, we present the first systematic exploration of cognitive heuristics in LLM-driven code vulnerability detection. We introduce a controlled framework that holds the code fixed and only varies the surrounding context to trigger three cognitive heuristics: the halo effect through author attribution, the framing effect through task objectives and consequences, and the anchoring effect through prior analysis results. Within this framework, we evaluate eight LLMs across three programming languages and perform both quantitative and code-level analyses. Our findings demonstrate that all evaluated models are susceptible to these heuristics. Cross-model average susceptibility is highest for framing at 33.2%, followed by anchoring at 23.5% and halo at 18.4%. Code-level analysis reveals that vulnerabilities that require semantic reasoning for detection are more susceptible to cognitive heuristics than those identifiable through pattern matching. Furthermore, models often change their verdict from safe to vulnerable based on the cognitive condition, without accurately identifying the actual vulnerability. To highlight the practical impact, we demonstrate a proof-of-concept black-box cognitive attack that can suppress up to 97% of previously detected vulnerabilities. These findings indicate that cognitive susceptibility is a consistent and exploitable property of LLM-based vulnerability detection.
许愿