HTTP header injection meaning, in plain words

HTTP header injection slips unwanted content into the extra data sent with a page. How a line break breaks the structure, what follows, and the fix IPA gives.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

HTTP header injection is a technique that slips unwanted content into the extra information sent with a page. A header is that extra information, sent along with the page itself. IPA explains that when the value of a header such as Location or Set-Cookie is built from input from outside, a line break code that gets mixed in breaks the separation of the headers.

How does HTTP header injection work?

Think of a parcel's shipping label. The address field should be one line, but suppose the writer breaks the line inside the field and adds another item. The courier reads the added content as a separate item.

In a web response too, each line is a separate item of the header, and everything after a blank line is the body. If input is used as it stands in a header value and a line break gets in, an arbitrary header or body text can be slipped in. An attack that splits one response into several is called an HTTP response splitting attack.

IPA's first countermeasure is not to build headers yourself by joining strings, but to use the API for outputting headers that the runtime environment or language provides. Where the API cannot be used, prevent line breaks yourself. Removing line breaks from the input is positioned as a safeguard. How to check is on the HTTP header injection vulnerability page.

Why does HTTP header injection matter?

IPA lists three impacts. Display of false information and embedding of scripts are threats of the same kind as XSS. If an arbitrary cookie can be stored in the user's browser, the login state may be affected.

The third is cache poisoning. If a reverse proxy (a relay device placed between users and the server) is made to remember a fake page, many users keep seeing the rewritten page for a long time. That one crafted request can reach widely is why it is taken seriously.

Places where outside input is used in header values are mostly the Location header, which shows the redirect destination, and Set-Cookie, which issues cookies. IPA gives these two as examples. Begin by finding those places. The free URL check reads only what is visible from outside.

Related terms

  • XSS: a technique with a similar impact, display of false content and embedding of programs.
  • CSP: also given in a response header, a setting that narrows where content may load from.

Next step

Ask your development or production staff whether your site builds headers from input values. How to check and fix it is on the HTTP header injection vulnerability page. To discuss an assessment, contact us.

Frequently asked questions

Why is a line break the problem in HTTP header injection?

A header holds one item per line, and a line break is what separates the items. If a line break gets into the input, the separation breaks, and another header or body text may be slipped in.

Is removing line breaks from the input enough?

It helps, but it is positioned as a safeguard. IPA points first to using the API for outputting headers. Where a field needs input that contains line breaks, removing them across the board can also spoil normal behaviour.

Frequently asked questions

Why is a line break the problem in HTTP header injection?

A header holds one item per line, and a line break is what separates the items. If a line break gets into the input, the separation breaks, and another header or body text may be slipped in.

Is removing line breaks from the input enough?

It helps, but it is positioned as a safeguard. IPA points first to using the API for outputting headers. Where a field needs input that contains line breaks, removing them across the board can also spoil normal behaviour.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.