The analysis of the security advisory and the associated commit 65301c194593d46a84623b64e5fde2f51d3550f6 reveals two primary vulnerabilities in the i18next-http-middleware package, both stemming from improper input sanitization of the user-provided language parameter (lng).
-
HTTP Response Splitting / DoS in handle(): The core of the vulnerability lies in the handle function in lib/index.js. This function used utils.escape() on the lng parameter before setting it as the Content-Language HTTP header. The escape function only performed HTML-entity encoding and failed to strip control characters like CR (\r) and LF (\n). This allowed attackers to inject raw CRLF sequences into the response headers. On Node.js versions before 14.6.0, this led to HTTP response splitting, enabling attacks like session fixation and cache poisoning. On newer Node.js versions, this would cause an ERR_INVALID_CHAR exception that, being unhandled by the middleware, would crash the process and cause a Denial of Service. The fix was to replace utils.escape() with a new utils.sanitizeHeaderValue() function that explicitly removes these control characters.
-
XSS Filter Bypass in hasXSS(): A related but distinct vulnerability was fixed in the hasXSS utility function in lib/utils.js. This function's regex for detecting event handlers was too specific, only matching handlers that appeared as the first attribute in an HTML tag. This allowed for a simple bypass. An attacker could craft a malicious language parameter that would pass the hasXSS check but still contain an executable XSS payload. If the application then rendered this language parameter on a page without proper escaping, it would lead to reflected XSS. The patch strengthens the regex to catch event handlers anywhere within a tag.
Both vulnerable functions, handle and hasXSS, would appear in a runtime profile during an exploit, as they are directly involved in processing the malicious input.