Indirect Prompt Injection in HTTP Headers: How to Test

Indirect Prompt Injection in HTTP Headers: How to Test

Indirect prompt injection through HTTP headers works for a dull reason: a header is just text, and a language model cannot tell the instructions it was given from the data it reads. Put a sentence in a Server value and a model that serialises the whole response will read it with the same attention it gives the page body. There is no parser boundary inside the context window. That is the whole vulnerability.

Most writing on indirect injection gives headers a line and moves on to poisoned web pages and documents. That is a mistake, because the header channel has properties the body does not: it is rarely sanitised, it is invisible in the interfaces humans review, and it runs in two directions at once.

Why HTTP Headers Became a Usable Injection Channel

Input validation, output encoding and content filtering are almost always aimed at the body. Teams sanitise HTML, strip script tags, run a classifier over the retrieved text. The metadata above it goes through untouched, because for twenty years headers have been treated as machine plumbing that nobody reads. They are read now.

Serialisation order matters more than people expect. When a fetch tool hands a response to the model, the status line and headers usually arrive first, with the body underneath. Header text so sits early in the context, in the position many implementations weight most heavily, ahead of the content it was supposed to summarise. An instruction placed there is not buried in the middle of forty kilobytes of markup. It is at the top.

How common is this in the wild? Public internet-scale scanning reported in October 2026 looked at roughly 217 million web responses and surfaced around thirty sites carrying instruction-style text in response headers. Treat those counts as indicative rather than precise, and read them the right way round: thirty in 217 million is not a wave, it is a cheap experiment that costs an attacker one line in an nginx config. The technique is being tried. It is not yet being scaled.

The final property is the one that makes triage hard. Nobody sees the payload. A reviewer checking the agent’s summary sees a paragraph of plausible prose, and the header that steered it never appears in the chat transcript, the screenshot or the ticket. If you are not logging the full serialised context sent to the model, you have no record of the attack at all.

Where Header Text Reaches the Model’s Context

Four patterns account for most real exposure:

  • Agentic browsing and fetch tools that return the whole response object, headers included, to be summarised or acted on.
  • AI-assisted log, WAF and alert triage, where attacker-controlled request headers arrive verbatim inside the text an assistant reads.
  • Retrieval and crawler pipelines that store response metadata alongside chunked page text, so the header travels into the vector store and resurfaces months later. A quiet variant of the usual RAG security risks, and harder to spot because the poisoned chunk looks like housekeeping.
  • MCP and custom HTTP tools returning raw responses, plus CI and observability dashboards that pipe build metadata and request fields into a model for explanation.

The inbound direction is the one teams forget, and it is usually the worse of the two. An outbound browsing agent reading a hostile site has whatever privileges you gave it. An inbound triage assistant reading your logs has internal tool access by design: ticketing, firewall rules, runbooks, sometimes the ability to close its own alerts. The attacker needs no account, no session and no access to your network. They need one HTTP request with a chosen User-Agent.

Consider the shape of it. An attacker sends a request whose User-Agent contains instructions. Hours later an assistant summarising the nginx logs calls the ticketing tool, closes the alert as benign and proposes an allowlist entry for the source IP. No model was jailbroken in any interesting sense. The agent did exactly what the text in front of it said, using privileges the attacker never had. That is the confused deputy relationship at the heart of agent tool use, and it is the part engineering can actually remove.

Which Headers to Probe, in Both Directions

Response Side

Start with the fields that survive proxies and get serialised by default: Server, X-Powered-By, Link, Set-Cookie, the filename value inside Content-Disposition, and the Location value on a redirect. Then invent your own vendor header, because X- anything is passed through by most stacks and copied into most serialisers without question. Redirect chains are worth extra attention: a tool that follows three hops may concatenate three sets of headers into one blob.

Request Side

User-Agent and Referer first, since both are logged verbatim almost everywhere. Then X-Forwarded-For, Host, Accept-Language, cookie names rather than cookie values, and deliberately malformed fields that logging pipelines preserve instead of rejecting. Anything that reaches a log line reaches the assistant reading the log line.

Encoding, Folding and Length

Plain English text is the control case. After that, test percent-encoding, Unicode escapes, obfuscated or lookalike characters, repeated headers of the same name, and a payload split across several fields so that no single header looks odd. Splitting works surprisingly often, because the model reassembles meaning that a regex never saw.

What Your Own Stack Normalises

Before you spend a day on clever payloads, measure the pipe. If the reverse proxy truncates at 8KB, drops non-ASCII, lowercases names or collapses duplicates, your budget is smaller than you think and your negative results are meaningless. Send a marker string of known length through the full path and read what arrives at the model. Test what the system does, not what the documentation claims it does.

A Test Plan That Proves Consequence, Not Output

Map Permissions Before You Write a Payload

List every tool the agent can call, every identity it borrows, every network path it can reach and every store it can write to. The exploitable surface is the intersection of that list with attacker-controlled text. Without it you will produce transcripts instead of findings, which is the failure mode of most AI red teaming work that starts from scope rather than from proof.

Build the Harness

You need two things. A controlled origin you own that returns configurable headers on demand, so you can vary one field at a time against a browsing or crawling agent. And a request generator for the inbound direction, pointed at a test environment whose logs feed the triage assistant you are assessing. Both should be yours, in scope, and agreed in writing.

Canaries the Server Observes

A model saying it will exfiltrate data is not a finding. It is prose. The finding is the HTTP request your canary host received, the seeded record that changed, the unused API path that was suddenly called, the DNS lookup for a unique subdomain you minted for that payload. Proof comes from your logs, never from the model’s own account of itself.

Take the pricing-page case: an agentic browser is asked to summarise a competitor’s page and receives a custom X- header telling it to fetch an internal path and append the result. The summary might read perfectly innocently. Check your authoritative DNS logs instead. If the unique subdomain was resolved, the agent made the call, and the wording of the summary is irrelevant.

Handle Non-determinism Honestly

One success is not a vulnerability and one failure is not safety. Run each payload a fixed number of times at pinned settings, report a success rate as a fraction of attempts, and record the model name, version, temperature and date. A provider update can change your result without a single line of code changing on your side, which is why undated single-shot results age badly. The same discipline applies across any structured approach to red teaming an LLM.

Writing Up a Header Injection Finding So It Gets Fixed

Rate by blast radius, not by cleverness. What did the tool call actually do, whose credentials did it borrow, what data crossed the boundary, and could the attacker repeat it without authentication? An inbound payload that closes alerts outranks an outbound payload that produces a rude summary, every time.

Give reproduction detail that survives a model update: the exact header name and value, byte for byte, the ordering and any other headers present, the success rate across runs, the model version and the date of testing. Then separate the two halves of the problem. Model behaviour is a probability you can reduce. The architecture flaw, an agent acting on untrusted text with privileges the author of that text never held, is a design decision you can delete. Engineering can close the second one. The first one, as the underlying mechanics of prompt injection make clear, is managed rather than removed.

One caution about tooling. Plenty of scanners declare a system vulnerable to prompt injection because one model graded another model’s reply. That is an assertion, not a measurement. Ask where the fact came from before it goes in a report, and if the answer is a judge model with no server-side evidence behind it, treat the result as a lead to verify. Automated red teaming has real blind spots here, and the judgement about whether something is a finding stays firmly human.

Map findings to references your stakeholders already accept: OWASP Top 10 for LLM Applications, LLM01 Prompt Injection, the relevant MITRE ATLAS techniques, and the NCSC and CISA Guidelines for Secure AI System Development.

Defences That Hold, and Defences That Only Look Like Fixes

Strip, allowlist and normalise headers before serialisation. Pass through the handful the agent genuinely needs, drop the rest, and keep metadata in a separate structured field rather than concatenated into prose. Structure is not a security boundary for a model, but it is better than paragraph soup, and it makes provenance marking possible.

Then assume the filter will be beaten. Scope tool permissions to the minimum the task requires. Gate state-changing and outbound calls behind human approval. Restrict egress so a fetch to an attacker domain fails at the network rather than at the model’s conscience. Log the full context sent to the model, because without it a post-incident review has nothing to read.

Classifier guardrails and instruction hardening belong in the stack, but be clear about what they do: they lower the hit rate. They do not close the hole, because the root cause is representational, not a missing filter. Retest after every change, and compare success rates rather than pass or fail verdicts.

Last, a data handling point that gets missed in the rush to automate triage. Capturing full HTTP traffic and feeding it to a hosted model means shipping cookies, session tokens, internal hostnames and personal data to a third party. Work out your lawful basis, your retention and your redaction before the pipeline goes live, not after.

The Short Version

Headers are an injection channel in their own right, not a footnote. Test both directions, because the inbound case usually holds more privilege. Prove consequence with canaries your own servers observe, repeat each payload and report a success rate with the model version and date. Stripping headers helps and does not fix it. Remove the confused deputy relationship, however much that dents the demo.

Frequently Asked Questions

Can indirect prompt injection really work through HTTP headers?

Yes, where header text reaches the model’s context. The model has no mechanism to treat a Server value differently from page content, and header text typically arrives first in a serialised response. Whether it works against a specific system depends on what your stack strips before serialisation, which is exactly what the test plan above measures.

Which HTTP headers should I test first?

Outbound, start with Server, X-Powered-By, Link, Content-Disposition filenames, redirect Location values and a custom X- header of your own. Inbound, start with User-Agent and Referer, then X-Forwarded-For, Host and Accept-Language. Confirm what survives your proxy before drawing conclusions from a negative result.

Does stripping headers before the model sees them fix the problem?

No, it narrows one channel. The same instruction can arrive through page body text, a retrieved document, a support ticket or a commit message. Stripping is worth doing, but it has to sit alongside scoped tool permissions, approval gates on state-changing actions and egress restrictions.

How do I tell a real finding from a model simply repeating an instruction it read?

Look for server-side evidence. A callback to a unique canary host, a changed seeded record, a call to an unused API path, an audit entry showing which identity acted. If the only evidence is the model saying it did something, you have a transcript rather than a finding.

Are retrieval pipelines and crawlers affected as well as browsing agents?

They are, and often more quietly. If a crawler stores response metadata alongside chunked page text, the injected header is persisted and can resurface in an unrelated answer weeks later. Check what your ingestion pipeline keeps, and mark provenance so retrieved content is never treated as instruction.