Words Speak Louder Than Code: Investigating Cognitive Heuristics in LLM-Based Code Vulnerability Detection
This paper presents the first systematic investigation demonstrating that LLM-based code vulnerability detection is significantly susceptible to human-like cognitive heuristics (framing, anchoring, and halo effects), which can alter model verdicts and be exploited to suppress up to 97% of detected vulnerabilities.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you have a super-smart robot security guard whose job is to look at computer code and decide: "Is this safe, or is it a ticking time bomb?"
For a long time, we assumed this robot only looked at the code itself—the logic, the math, the structure. But this paper reveals a startling truth: The robot doesn't just read the code; it reads the story around the code. And just like humans, this robot has mental shortcuts (called "cognitive heuristics") that can trick it into making the wrong call.
Here is the breakdown of their findings, using simple analogies.
The Three Ways the Robot Gets Tricked
The researchers tested three specific ways to "hack" the robot's mind without changing a single line of code. They simply changed the context (the metadata) surrounding the code.
1. The Halo Effect (The "Celebrity" Bias)
The Analogy: Imagine a judge in a courtroom. If the defendant is a famous, respected CEO, the judge might subconsciously think, "He's a good person, he wouldn't do anything wrong," and be more lenient. If the defendant is a young, unknown intern, the judge might think, "He's inexperienced, he probably messed up," and be stricter.
The Finding:
- When the code was attributed to a "Principal Security Engineer" (a high-status expert), the robot became lazy and trusting. It missed real vulnerabilities because it assumed, "An expert wouldn't write bad code."
- When the same code was attributed to a "Junior Developer" (a low-status novice), the robot became suspicious and paranoid. It found the vulnerabilities it missed before, but it also started crying "Wolf!" on safe code, creating false alarms.
- The Twist: Some robots (like the one named Claude) did the exact opposite, trusting the junior more than the expert, but the bias was still there.
2. The Framing Effect (The "Warning Label" Bias)
The Analogy: Think of a medicine bottle.
- Label A: "This medicine cures 90% of patients." (Positive frame)
- Label B: "This medicine fails to cure 10% of patients." (Negative frame)
Even though the math is the same, your reaction changes.
The Finding:
- Positive Frame: When the robot was told, "Your job is to make sure the pipeline runs smoothly and avoid false alarms," it became too relaxed. It ignored dangerous bugs to keep things moving fast.
- Negative Frame: When the robot was told, "Your job is to find security threats before they destroy the system," it became hyper-vigilant. It found more bugs, but it also started flagging safe code as dangerous.
- The Result: This was the strongest trick of all. Every single robot tested was swayed by how the task was described.
3. The Anchoring Effect (The "First Impression" Bias)
The Analogy: If you ask a friend, "Is this house worth $500k?" and they say "Yes," you might think it's a bargain. If you ask, "Is this house worth $1M?" and they say "No," you might think it's cheap. The first number you hear "anchors" your judgment.
The Finding:
- If the robot was told, "A previous scan said this code is SAFE," it tended to agree and miss new bugs.
- If it was told, "A previous scan said this code is VULNERABLE," it tended to agree and find bugs (even if they weren't there).
- The robot was essentially saying, "Well, the other guy said it's safe, so I'll trust that," instead of doing its own independent work.
The Big Problems Discovered
The researchers found three major issues with how these robots work:
1. The "Volume Knob" Problem
The robots didn't get smarter or dumber at finding bugs. They just got louder or quieter.
- When the context made them suspicious, they turned the "Volume Knob" up: They flagged everything as dangerous (finding real bugs, but also lots of false alarms).
- When the context made them trusting, they turned the "Volume Knob" down: They flagged nothing (missing real bugs, but also having fewer false alarms).
- The Takeaway: The robot didn't actually learn to distinguish good code from bad code better; it just changed its mood.
2. The "Hallucination" Trap
When the robot was tricked into thinking a safe code was dangerous (due to a "Junior Developer" label or a "Vulnerable" anchor), it didn't just say "It's dangerous." It often made up a fake reason.
- Example: The robot saw safe code but, because it was in a "suspicious" mood, it claimed, "This looks like a memory leak!" when there was no leak. It was confident, but completely wrong.
3. The "Smart" vs. "Dumb" Code
- Easy Bugs: Some bugs are obvious, like a typo or a missing semicolon. The robot found these easily, no matter what the context was.
- Hard Bugs: Some bugs require deep thinking (like tracking how a variable changes over time). These were the ones the robot got tricked on the most. If the context was "trusting," it missed the hard bugs. If the context was "suspicious," it invented fake hard bugs.
The "Cognitive Attack" (The Real-World Danger)
The researchers didn't just stop at testing; they built a proof-of-concept attack.
Imagine a hacker wants to sneak a dangerous piece of code into a company's software. Instead of trying to hack the robot's brain directly (which is hard), the hacker just fakes the paperwork.
- They write the code.
- They attach a fake email saying it comes from a famous security expert (Halo).
- They write a note saying, "Let's keep the pipeline moving, don't be too picky" (Framing).
- They attach a fake report saying, "Previous scans said this is safe" (Anchoring).
The Result: The robot, seeing this "reassuring" package, decided the dangerous code was SAFE. The attack successfully suppressed up to 97% of the vulnerabilities the robot would have normally caught.
The Bottom Line
This paper proves that Large Language Models (LLMs) used for security are not objective machines. They are influenced by the same psychological tricks that influence humans.
- They trust the wrong people (experts too much, juniors too little).
- They react to how you ask the question (fear vs. comfort).
- They get stuck on first impressions (previous reports).
The most dangerous part? You don't need to be a genius hacker to break them. You just need to know how to write a convincing email or a nice-looking commit message. The robot isn't broken; it's just human-like in its flaws.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.