Skip to main content
LLM Security Database
Skip to research details
Back to research findings
LMVD-ID: 613c6d23
Paper published October 1, 2024
Entry analyzed December 29, 2024
Paper-reported evidence
Confidence: Source-linked

The LMVD-ID is an internal research identifier, not an official CVE identifier.

Context-Shifting Code Injection

Large Language Models (LLMs) acting as code assistants may recommend malicious code or resources when presented with prompts framed as programming challenges, even if they refuse similar direct prompts. This occurs due…

BibTeX citation

Paper-evaluated models(1)

  • GPT-4

Description

Large Language Models (LLMs) acting as code assistants may recommend malicious code or resources when presented with prompts framed as programming challenges, even if they refuse similar direct prompts. This occurs due to insufficient context-aware safety mechanisms. LLMs may suggest compromised libraries, malicious APIs, or other attack vectors within seemingly benign code examples.

Examples

See accompanying paper for detailed examples demonstrating how LLMs, when prompted within a coding context (e.g., a specific programming challenge), recommend using compromised npm packages, malicious GitHub repositories, or blacklisted APIs despite rejecting direct requests for malicious code generation. Examples include recommendations for code that utilizes known vulnerable libraries or incorporates malicious functionality through seemingly innocuous code snippets.

Impact

Successful exploitation allows attackers to introduce malicious code into software projects through seemingly legitimate LLM-suggested code. This results in supply chain attacks, enabling malware deployment, data exfiltration, or other malicious activities targeting users of the affected software. The scale of impact depends on the popularity and distribution of the affected software.

Affected Systems

Systems using LLMs as code assistants, especially those directly integrating LLM outputs into codebases without thorough security review, are vulnerable. This can include various IDE plugins and development workflows that leverage LLMs for code suggestions.

Mitigation Steps

  • Implement robust context-aware safety mechanisms in LLMs to prevent the recommendation of malicious code or resources, even within embedded prompts.
  • Conduct thorough security reviews of all code generated or recommended by LLMs, including careful scrutiny of external dependencies.
  • Regularly update LLMs with information on newly discovered vulnerabilities and malicious resources.
  • Educate developers about the potential risks of directly integrating LLM suggestions into their projects without proper scrutiny.
  • Employ static and dynamic code analysis tools to detect malicious code introduced indirectly through seemingly benign LLM suggestions.

Research context and confidence

Evidence and verification
Paper-reported; independent reproduction is not documented.
Primary research source linked.
Severity
Not rated by this catalog.
Source and publication type
arXiv · Research preprint.
Peer-review status is not provided by this source.
Author and publication status
Author metadata is not stored; see the primary paper.
Threat model and attacker access
Black-box model, service, or application access.
Related deployment categories
No related deployment category is classified.
Taxonomy labels only; paper-specific deployment prerequisites are not inferred.
Affected systems
Systems using LLMs as code assistants, especially those directly integrating LLM outputs into codebases without thorough security review, are vulnerable. This can include various IDE plugins and development workflows…

Research Paper

Hallucinating AI Hijacking Attack: Large Language Models and Malicious Code Recommenders

Primary source: arXiv. Findings are reported by the cited research and have not been independently verified.

View Paper

Evidence

This entry is based on a primary research source. Its findings are paper-reported; independent reproduction and verification are not claimed.

https://arxiv.org/abs/2410.06462