# Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') (CWE-113) The product receives data from an HTTP agent/component, and it places this data in HTTP response headers without neutralizing CRLF sequences. - Prevalence: Média 3 linguagens cobertas - Impact: Alto 2 regras de severidade alta - Prevention: Documentada 3 exemplos de correção **OWASP:** Injection (A03:2021-Injection) - #3 ## Description An attacker can inject CRLF sequences into HTTP headers to create additional headers or response body content. This can lead to cache poisoning, cross-site scripting, or other attacks. ## Prevention Estratégias de prevenção para HTTP Response Splitting baseadas em 3 regras de detecção do Shoulder. ### Go Strip CRLF characters from user input before setting HTTP headers ### Python Strip CRLF characters from user input before using in HTTP headers ## Warning Signs - [HIGH] user input flowing into HTTP response headers without CRLF sanitization - [MEDIUM] user input flowing to HTTP headers without CRLF sanitization ## Consequences - Executar código não autorizado - Burlar mecanismo de proteção - Modificar dados da aplicação ## Mitigations - Nunca inclua entrada do usuário diretamente em cabeçalhos de resposta HTTP - Sanitize toda entrada do usuário que possa ser incluída em cabeçalhos - Use os métodos fornecidos pelo framework para definir cabeçalhos, que cuidam da codificação ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **HTTP Header Injection** [MEDIUM]: Detects user input flowing to HTTP headers without CRLF sanitization. - Remediation: Remove CRLF characters from user input before setting headers. ```go value := strings.ReplaceAll(userInput, "\r", "") value = strings.ReplaceAll(value, "\n", "") w.Header().Set("X-Custom", value) ``` Learn more: https://shoulder.dev/learn/go/cwe-113/header-injection ### Javascript (1 rules) - **HTTP Header Injection (Response Splitting)** [HIGH]: Detects user input flowing into HTTP response headers without CRLF sanitization. - Remediation: Remove CRLF characters from user input before setting headers. ```javascript const sanitized = userInput.replace(/[\r\n]/g, ''); res.setHeader('X-Custom-Header', sanitized); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-113/header-injection ### Typescript (1 rules) - **HTTP Header Injection (Response Splitting)** [HIGH]: Detects user input flowing into HTTP response headers without CRLF sanitization. - Remediation: Remove CRLF characters from user input before setting headers. ```javascript const sanitized = userInput.replace(/[\r\n]/g, ''); res.setHeader('X-Custom-Header', sanitized); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-113/header-injection ### Python (1 rules) - **HTTP Header Injection** [HIGH]: Detects user input flowing into HTTP response headers without CRLF sanitization. - Remediation: Remove CRLF characters from header values. ```python import re safe_value = re.sub(r'[\r\n]', '', user_value) ``` Learn more: https://shoulder.dev/learn/python/cwe-113/header-injection