CLOUD CONCEPT

Prompt Injection

Prompt injection is an attack in which untrusted input attempts to make a generative AI model follow instructions that conflict with the application's intended behavior or security policy.

Cloud Concepts Hub →

What is Prompt Injection

Language models process instructions and reference material together, creating opportunities for attackers to disguise malicious commands as ordinary content. In cloud applications, successful injection can manipulate responses, expose sensitive context, or trigger unauthorized tool actions, so defenses must combine model-level guardrails with independently enforced security controls.

Prompt injection exploits the difficulty language models have distinguishing trusted instructions from untrusted content. An attacker supplies text or other model-readable material that attempts to redirect the model, override application rules, or influence subsequent actions. Unlike traditional code injection, the payload may be ordinary language rather than executable syntax. A successful attack does not necessarily compromise the underlying model infrastructure; it can instead misuse the application's legitimate access and capabilities.

Direct injection arrives through an attacker-controlled user message. Indirect injection arrives through material the application retrieves or processes, such as a web page, document, support ticket, repository file, or tool response. For example, a retrieval-augmented generation application might retrieve a document containing an instruction to ignore the user's question and send confidential context to an external address. Storing that document in a trusted cloud bucket does not make its embedded instructions trustworthy.

Start protection at trust boundaries. Keep system instructions separate from user input and retrieved material, clearly identify external content as data, and avoid placing credentials or unnecessary sensitive information in model context. These measures improve instruction handling but do not establish a reliable security boundary. Apply authorization before retrieval so users receive only documents they may access; a vector similarity match is not an authorization decision.

Use input screening and model guardrails to detect suspicious instruction patterns, policy violations, and attempts to override application behavior. Evaluate retrieved content and tool responses as well as user messages. On AWS, Amazon Bedrock Guardrails provides prompt attack filtering, but applications must correctly configure the policy and identify the input content to evaluate. Do not assume every orchestration step or retrieved passage is automatically protected. Filters can miss attacks and can block legitimate requests, so test both detection coverage and false positives.

The strongest controls limit what an injected model can accomplish. Treat a model-generated tool call as a proposed action, not authorization. A tool gateway or backend must validate arguments, authenticate the caller, enforce tenant boundaries, and independently authorize the operation. Use narrowly scoped execution roles, restrict outbound network destinations, and require approval for consequential actions such as deleting resources or exporting records. An agent that summarizes invoices should not have unrestricted storage access or permission to initiate payments.

Validate model outputs before sending them to browsers, databases, shells, or downstream APIs. Use structured schemas, parameterized queries, safe rendering, and allowlisted operations rather than executing generated text. Output filtering can reduce sensitive-data disclosure, but it cannot undo a tool action that has already occurred. Similarly, encryption and private networking protect other parts of the system but do not prevent malicious instructions in authorized content.

For security design and exam scenarios, recognize prompt injection as an OWASP Top 10 for LLM Applications risk and apply defense in depth. Jailbreaking overlaps with prompt injection but specifically targets model safety restrictions; prompt injection can also target business workflows without requesting prohibited content. Red-team direct and indirect attack paths, record guardrail decisions and tool activity, and retest after changes to prompts, models, retrieval pipelines, or permissions. Stronger filtering and approval workflows introduce latency and operational friction, but independently enforced authorization limits damage even when the model follows an attacker's instructions.

Key aspects of Prompt Injection

Prompt injection defense combines explicit trust boundaries, guardrail evaluation, independently enforced permissions, safe tool execution, and recurring adversarial testing.

Untrusted content can carry instructions

Treat user messages, retrieved documents, and tool responses as potential attack surfaces. Content does not become trustworthy merely because it was indexed or stored in an internal repository.

Instruction separation is not authorization

Separate application instructions from external data and explicitly label reference content. Enforce access decisions outside the model because prompt wording cannot reliably prevent unauthorized behavior.

Layered detection and guardrails

Screen relevant inputs and outputs using policies suited to the application's risks. Measure false positives and missed attacks, and verify that indirect content actually passes through the intended checks.

Least-privilege tool execution

Give each backend only the permissions its task requires and validate every proposed tool action. Require independent authorization and, where appropriate, human approval before sensitive or irreversible operations.

Safe downstream consumption

Treat generated text and tool arguments as untrusted input to other systems. Validate schemas, constrain operations, and use safe rendering or parameterized interfaces instead of executing free-form output.

Continuous adversarial testing

Test attacks delivered through both user input and external content, including attempts to exfiltrate data or misuse tools. Correlate model interactions with backend actions while limiting sensitive information in logs.

Cloud services for Prompt Injection

Amazon Bedrock provides model access and guardrail capabilities, while IAM constrains the AWS permissions available to the application and its tools. Lambda handlers can independently validate arguments and authorize requested actions before execution. Where the architecture routes relevant traffic through it, AWS Network Firewall adds destination restrictions that reduce opportunities for external data transfer. CloudWatch collects operational evidence for detection and investigation. These services address different boundaries: model filtering reduces suspicious instruction handling, backend controls prevent unauthorized actions, network controls restrict communication, and monitoring identifies failures. None makes untrusted content safe by itself.

Amazon Bedrock

Amazon Bedrock Guardrails supports prompt attack filtering as part of a broader guardrail policy. Configure the relevant input evaluation correctly and integrate checks into the application's processing paths; filtering does not replace retrieval authorization or backend tool permissions.

Open Amazon Bedrock →
AWS Lambda image AWS Lambda

Lambda can host tool handlers that validate model-generated arguments and enforce application authorization before accessing resources. Use narrowly scoped execution roles and expose specific operations rather than a general-purpose command executor.

Open AWS Lambda →
AWS Firewall Manager image AWS Network Firewall

AWS Network Firewall can restrict outbound traffic from supported VPC architectures when that traffic is routed through its endpoints. Destination controls help limit data exfiltration by compromised application workflows, but do not inspect model intent or cover traffic that bypasses the firewall.

Open AWS Network Firewall →
Amazon CloudWatch image Amazon CloudWatch

CloudWatch can collect application logs and metrics for guardrail interventions, rejected tool calls, and unusual execution patterns. Correlate events using request identifiers and avoid indiscriminately recording sensitive prompts or retrieved content.

Open Amazon CloudWatch →