1. Home
  2. Web App Vulnerabilities
  3. How to remediate – Response Splitting

How to remediate – Response Splitting

1. Introduction

Response Splitting is a web vulnerability where attackers can manipulate HTTP response headers. This allows them to inject arbitrary content, potentially leading to session hijacking, cross-site scripting (XSS), and cache poisoning. Web applications that dynamically generate responses based on user input are usually affected. Successful exploitation could compromise the confidentiality, integrity, and availability of web services.

2. Technical Explanation

HTTP response splitting occurs when untrusted data is included in HTTP response headers without proper sanitisation. Attackers exploit this by injecting Carriage Return (`/r`) and Line Feed (`n`) characters into the input, which are interpreted as header separators. This allows them to construct their own arbitrary headers and body, effectively controlling the second response sent by the server.

  • Exploit mechanism: An attacker submits input containing `/r` and `/n` characters. The server includes this input in a header, splitting the response. The attacker then injects additional headers to control subsequent requests or responses. For example, injecting `rnX-Custom-Header: malicious_value` could add a custom header.
  • Scope: Web applications using any server-side language (PHP, Java, Python, etc.) that dynamically construct HTTP responses are potentially affected.

3. Detection and Assessment

Confirming vulnerability requires checking how the application handles user input in headers. A quick check involves looking for version information or specific settings related to header handling. Thorough assessment means testing with known malicious payloads.

  • Quick checks: Check web server configuration files (e.g., Apache’s httpd.conf, Nginx’s nginx.conf) for any custom header processing rules.
  • Scanning: Burp Suite or OWASP ZAP can be used with a payload designed to trigger response splitting. These tools may flag the vulnerability if detected.
  • Logs and evidence: Examine web server access logs for unusual headers or multiple responses from a single request. Look for patterns containing `/r` or `/n`.
curl -H "X-Test: testrnX-Custom: malicious" http://example.com

4. Solution / Remediation Steps

4.1 Preparation

  • Ensure you have a rollback plan to revert to the previous configuration if issues arise. A simple code or config restore is usually sufficient.
  • Change windows should be scheduled during off-peak hours with approval from relevant stakeholders.

4.2 Implementation

  1. Step 1: Identify all locations in your application code where user input is used to construct HTTP response headers.
  2. Step 3: If setting cookie values, ensure they are properly encoded to prevent injection attacks.

4.3 Config or Code Example

Before

header("X-Custom: " . $_GET['input']);

After

header("X-Custom: " . str_replace(array("r", "n"), "", $_GET['input']));

4.4 Security Practices Relevant to This Vulnerability

Several security practices can help prevent response splitting attacks. Input validation is crucial, as is the principle of least privilege.

  • Practice 2: Least Privilege – Limit the permissions of the web server process to reduce the impact if an attacker successfully exploits a vulnerability.

4.5 Automation (Optional)

Automated code scanning tools can help identify potential response splitting vulnerabilities during development.

# Example using grep to find potentially vulnerable code in PHP files
grep -n "header(" . $_GET | grep "r"

5. Verification / Validation

Confirm the fix by re-testing with malicious payloads and verifying that they are no longer successful. A smoke test should ensure core application functionality remains intact.

  • Post-fix check: Run the same `curl` command used for detection (see section 3) and verify that the response does not contain injected headers.
  • Re-test: Repeat the scanning process from section 3 to confirm that the vulnerability is no longer flagged.
  • Monitoring: Monitor web server logs for any unusual headers or multiple responses per request.
curl -H "X-Test: testrnX-Custom: malicious" http://example.com

6. Preventive Measures and Monitoring

Regular security baselines, code reviews, and CI/CD pipeline checks can help prevent response splitting vulnerabilities.

  • Baselines: Update your security baseline to include rules for input validation and header sanitisation.
  • Pipelines: Integrate SAST (Static Application Security Testing) tools into your CI/CD pipeline to automatically scan code for potential vulnerabilities, including response splitting.
  • Asset and patch process: Implement a regular patch management cycle to ensure that all software components are up-to-date with the latest security fixes.

7. Risks, Side Effects, and Roll Back

Incorrect sanitisation could break legitimate functionality or introduce new vulnerabilities. Always have a rollback plan in place.

  • Risk or side effect 1: Overly aggressive sanitisation might prevent valid characters from being used in headers, breaking application features.
  • Risk or side effect 2: Incorrect implementation of input validation could leave the application vulnerable to other injection attacks.
  • Roll back: Restore the previous version of your code and configuration files. Restart affected services.

8. References and Resources

Updated on December 27, 2025

Was this article helpful?

Related Articles