CWE Glossary

CWE is a trademark of the MITRE Corporation.

Stay in touch

Application security insights and invitations to exclusive events in your inbox


Your data will stay confidential Private and Confidential

HTTP Response Splitting [CWE-113]

This weakness describes improper neutralization of CRLF sequences in HTTP headers.

Created: September 11, 2012
Latest Update: August 5, 2015

Table of Content

  1. Description
  2. Potential impact
  3. Attack patterns
  4. Affected software
  5. Severity and CVSS Scoring
  6. Mitigations
  7. Vulnerability Remediation Techniques and Examples
  8. References

1. Description

This weakness occurs when software accepts data from an upstream provider, but does not neutralize or incorrectly neutralizes CR and LF characters before including data into HTTP response headers. This provides an attacker with ability to inject arbitrary headers into the HTTP response, which is sent to a client. As a result an attacker might be able to modify contents of the HTTP response by means of unexpected CR (carriage return - %0d or \r) and LF (line feed - %0a or \n) characters and send to the browser two different HTTP responses instead of one. The attacker, who controls the second HTTP response, can perform different attacks such as cache poisoning and cross-site scripting.

HTTP response splitting might occur when an application receives data from an untrusted source, such as HTTP request, or when data is not validated before sending it back to the client in HTTP response. Modern programming languages have built-in protection mechanisms against HTTP response splitting that do not allow sending more than one response header to client browser, so the HTTP response splitting attack is possible only when application uses untrusted input to construct headers.


1.1 PERL

The following example works with PERL and demonstrates the vulnerable code:

  1. use CGI qw(:standard);
  2. my $value = param('cookie');
  3. print "Content-type: text/plain\n";
  4. print "Set-Cookie: cookie=$value\n";

The example below redirects users to the address passed via the "page" parameter. The client sends the following header and receives the HTTP 302 response:
GET /test.pl?page=/index.html HTTP/1.1
HOST: testhost.local
Referer: testhost.local
ACCEPT: */*
Accept-Encoding: None
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Connection: Close
Accept-Transfer-Encoding: None

HTTP/1.1 302 Found
Date: Fri, 07 Sep 2012 17:02:45 GMT
Server: Apache

Location: /index.html
Content-Length: 0
Connection: close
Content-Type: text/html; charset=Windows-1252

If an attacker sends CRLF characters to vulnerable "page" parameter, he can split the header and make the client browser execute arbitrary HTML and script code:
GET /test.pl?page=%0d%0aContent-Type: text/html%0d%0aHTTP/1.1 200 OK%0d%0aContent-Type: text/html%0d%0a%0d%0a%3Chtml%3E%3Cfont color=red%3ECSRF%3C/font%3E%3C/html%3E HTTP/1.1
HOST: testhost.local
Referer: testhost.local
ACCEPT: */*
Accept-Encoding: None
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Connection: Close
Accept-Transfer-Encoding: None


1.2 ASP.NET

With ASP.NET 2.0 this attack is almost impossible, because the "\r\n" sequences are disallowed by default in methods that involve HTTP response headers. It is possible though to turn off HTTP response splitting protection by disabling the "enableHeaderChecking" option in web.config. Make sure this option is set to true.


1.3 PHP

PHP is not vulnerable to HTTP response splitting since version 5.1.2.

2. Potential impact

An attacker might be able to perform cross-site scripting, phishing and cache poisoning attacks. This weakness is a significant threat for high load servers that use caching proxies to deliver content to the end-users. One request sent by an attacker can be cached and displayed to all visitors of a webpage. As a result, an attacker might be able to gain access to potentially sensitive data and perform different attacks against website users.

3. Attack patterns

CAPEC has the following patterns for this weakness:


This weakness is described in WASC classification as four separate techniques:

4. Affected software

Any software that uses input data to construct headers is potentially vulnerable to this weakness. In most cases these are web applications, web servers, caching proxies.

5. Severity and CVSS Scoring

Depending on potential damage this weakness could impact integrity of the application and is usually scored as:
4.3 (AV:N/AC:M/Au:N/C:N/I:P/A:N) – Medium severity.


We use CVSSv2 scoring system in our HTB Security Advisories to calculate the risk of the discovered vulnerabilities. Not all of the vulnerabilities are scored in strict accordance to FIRST recommendations. Our CVSSv2 scores are based on our long internal experience in software auditing and penetration testing, taking into consideration a lot of practical nuances and details. Therefore, sometimes they may differ from those ones that are recommended by FIRST.

6. Mitigations

All input passed to the application must be considered untrustworthy and should be handled as such. Use a good known input validation strategy based on whitelists to construct headers and do not rely exclusively on looking for malicious or malformed inputs. All input should be decoded and canonicalized to the application's current internal representation.

7. Vulnerability Remediation Techniques and Examples

PHP

Usage of the header() function for HTTP headers output is safe in modern PHP versions.

PERL
  1. $param=~s/[\r\n]//gi;
ASP.NET

With ASP.NET 2.0 this attack is impossible, the "\r\n" sequences are disallowed by default.

Python
  1. param = re.sub("[^\\n\\r]+", "_", param)
JAVA/JSP
  1. url = url.replaceAll("\\n\\r","");
  2. response.sendRedirect(url);

These are general recommendations. Every case must be treated separately.

Caution: do not blindly copy-paste the above-mentioned solutions into your application code. In some cases this may result in incorrect behavior of the application or inconsistent patch. Carefully read the References or consult security specialists in case you are not sure how to patch a vulnerability.

8. References

  1. CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') [cwe.mitre.org]
  2. HTTP Response Splitting [www.owasp.org]
  3. HTTP Response Splitting Attack [resources.infosecinstitute.com]
  4. Introduction to HTTP Response Splitting [www.securiteam.com]

Copyright Disclaimer: Any above-mentioned content can be copied and used for non-commercial purposes only if proper credit to High-Tech Bridge is given.

↑ Back to Top
High-Tech Bridge on Facebook High-Tech Bridge on Twitter High-Tech Bridge on LinkedIn High-Tech Bridge RSS Feeds Send by Email
Share
Let's Talk