How does prompt injection happen?
OWASP lists it as LLM01 in its risk list for large language model applications. In its definition, user prompts alter the model's behaviour or output in unintended ways, and an instruction can work even when people cannot see it, as long as the model parses it [1]. In a direct injection, the prompt a user types steers the model, whether on purpose or by accident. In an indirect injection, the model takes in content from outside sources such as websites or files, and instructions hidden there change what it does [1].
NIST's Generative AI Profile describes the indirect form as adversaries exploiting LLM-integrated applications remotely, without a direct interface, by planting prompts in data the system is likely to retrieve. Security researchers have shown that this can be used to steal proprietary data or run malicious code on a remote machine [2].
Take one of OWASP's scenarios: a user asks a model to summarise a web page, and hidden instructions on that page make the model insert an image linking to an outside URL. Loading that image can leak the private conversation [1].
How can prompt injection be mitigated?
OWASP recommends narrowing the model's task in the system prompt, filtering inputs and outputs, granting least privilege, keeping untrusted content apart, requiring human approval for privileged actions and running adversarial tests. The same page admits it is unclear whether any fool-proof prevention exists, so these measures reduce impact rather than remove the risk [1]. NIST likewise notes that generative AI widens the attack surface, since the systems themselves are open to attacks such as prompt injection and data poisoning [2].