The vulnerability lies in BlackSheep's HTTP client implementation, specifically in the functions responsible for serializing an HTTP request object into raw bytes. The core issue is the lack of input sanitization for carriage return (CR) and line feed (LF) characters in several key functions within the blacksheep.scribe module.
-
blacksheep.scribe.write_header: This function constructs a single header line. Before the patch, it directly concatenated the header name and value, allowing malicious input containing CRLF sequences to inject new, attacker-controlled headers.
-
blacksheep.scribe.write_request_method: This function writes the HTTP method to the request line. It lacked validation, permitting an attacker to provide a method string with CRLF characters, which could be used to prematurely end the request line and start injecting other headers or even a second, malicious HTTP request (HTTP Request Splitting).
-
blacksheep.scribe.write_request_uri: This function constructs the URI part of the request line. It failed to sanitize the URL's path and query components, allowing CRLF characters in these fields to be written directly into the outgoing request, leading to a similar injection vector as with the method.
The patch addresses these vulnerabilities by introducing a _nocrlf utility function that strips \r and \n characters from the input and applying it to header values, URL paths, and queries. Additionally, it enforces strict validation on the HTTP method to ensure it conforms to RFC 7230 token standards, preventing injection through that vector. Any application using BlackSheep's ClientSession to make HTTP requests with user-controllable input for the method, URL, or headers was vulnerable.