CWEweakness
CWE-1427 Improper Neutralization of Input Used for LLM Prompting
- Alternate terms
- prompt injection
- Abstraction
- Base
- Structure
- Simple
- Status
- Incomplete
- Languages
- Not Language-Specific
- CWE version
- 5.0
Description
The product uses externally-provided data to build prompts provided to
large language models (LLMs), but the way these prompts are constructed
causes the LLM to fail to distinguish between user-supplied inputs and
developer provided system directives.
Extended description
When prompts are constructed using externally controllable data, it is
often possible to cause an LLM to ignore the original guidance provided by
its creators (known as the "system prompt") by inserting malicious
instructions in plain human language or using bypasses such as special
characters or tags. Because LLMs are designed to treat all instructions as
legitimate, there is often no way for the model to differentiate between
what prompt language is malicious when it performs inference and returns
data. Many LLM systems incorporate data from other adjacent products or
external data sources like Wikipedia using API calls and retrieval
augmented generation (RAG). Any external sources in use that may contain
untrusted data should also be considered potentially malicious.
Common consequences
• Confidentiality, Integrity, Availability: Execute Unauthorized Code or Commands, Varies by Context — The consequences are entirely contextual, depending on the
system that the model is integrated into. For example, the consequence
could include output that would not have been desired by the model
designer, such as using racial slurs. On the other hand, if the
output is attached to a code interpreter, remote code execution (RCE)
could result.
• Confidentiality: Read Application Data — An attacker might be able to extract sensitive information from the model.
• Integrity: Modify Application Data, Execute Unauthorized Code or Commands — The extent to which integrity can be impacted is dependent on
the LLM application use case.
• Access Control: Read Application Data, Modify Application Data, Gain Privileges or Assume Identity — The extent to which access control can be impacted is dependent
on the LLM application use case.
Potential mitigations
• [Architecture and Design] LLM-enabled applications should be designed to ensure
proper sanitization of user-controllable input, ensuring that no
intentionally misleading or dangerous characters can be
included. Additionally, they should be designed in a way that ensures
that user-controllable input is identified as untrusted and
potentially dangerous.
• [Implementation] LLM prompts should be constructed in a way that
effectively differentiates between user-supplied input and
developer-constructed system prompting to reduce the chance of model
confusion at inference-time.
• [Architecture and Design] LLM-enabled applications should be designed to ensure
proper sanitization of user-controllable input, ensuring that no
intentionally misleading or dangerous characters can be
included. Additionally, they should be designed in a way that ensures
that user-controllable input is identified as untrusted and
potentially dangerous.
• [Implementation] Ensure that model training includes training examples
that avoid leaking secrets and disregard malicious inputs. Train the
model to recognize secrets, and label training data
appropriately. Note that due to the non-deterministic nature of
prompting LLMs, it is necessary to perform testing of the same test
case several times in order to ensure that troublesome behavior is not
possible. Additionally, testing should be performed each time a new
model is used or a model's weights are updated.
• [Installation, Operation] During deployment/operation, use components that operate externally to the system to
monitor the output and act as a moderator. These components are called
different terms, such as supervisors or guardrails.
• [System Configuration] During system configuration, the model could be
fine-tuned to better control and neutralize potentially dangerous
inputs.
Detection methods
• Dynamic Analysis with Manual Results Interpretation: Use known techniques for prompt injection and other attacks, and
adjust the attacks to be more specific to the model or system.
• Dynamic Analysis with Automated Results Interpretation: Use known techniques for prompt injection and other attacks, and
adjust the attacks to be more specific to the model or system.
• Architecture or Design Review: Review of the product design can be effective, but it works best in conjunction with dynamic analysis.
Observed examples
• CVE-2023-32786: Chain: LLM integration framework has prompt injection
(CWE-1427) that allows an attacker to force the service to retrieve
data from an arbitrary URL, essentially providing SSRF (CWE-918) and
potentially injecting content into downstream tasks.
• CVE-2024-5184: ML-based email analysis product uses an
API service that allows a malicious user to inject a
direct prompt and take over the service logic, forcing
it to leak the standard hard-coded system prompts
and/or execute unwanted prompts to leak sensitive
data.
• CVE-2024-5565: Chain: library for generating SQL via LLMs using RAG uses
a prompt function to present the user with visualized results,
allowing altering of the prompt using prompt injection (CWE-1427) to
run arbitrary Python code (CWE-94) instead of the intended
visualization code.
• CVE-2024-48746: AI-based integration with business intel dashboard allows prompt injection through its natural language component, allowing execution of arbitrary code
Related
Observed example · CVE (4)
- CVE-2024-48746 An issue in Lens Visual integration with Power BI v.4.0.0.3 allows a remote attacker to execute arbitrary code via the Natural language… vulnerability
- CVE-2024-5184 The EmailGPT service contains a prompt injection vulnerability. vulnerability
- CVE-2024-5565 The Vanna library uses a prompt function to present the user with visualized results, it is possible to alter the prompt using prompt… vulnerability
- CVE-2023-32786 In Langchain through 0.0.155, prompt injection allows an attacker to force the service to retrieve data from an arbitrary URL, essentially… vulnerability
Child of · CWE (1)
- CWE-77 Improper Neutralization of Special Elements used in a Command weakness