CRLF injection in Refit's [Header], [HeaderCollection] and [Authorize] attributes
Date: 2024-11
Affected: nuget/Refit
Attack vector: ssrf
Category: vulnerability-disclosure
Severity: Critical
CVE: CVE-2024-51501
CWE: CWE-93
CVSS: 9.8 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

### Summary The various header-related Refit attributes (Header, HeaderCollection and Authorize) are vulnerable to CRLF injection. ### Details The way HTTP headers are added to a request is via the `HttpHeaders.TryAddWithoutValidation` method: <https://github.com/reactiveui/refit/blob/258a771f44417c6e48e103ac921fe4786f3c2a1e/Refit/RequestBuilderImplementation.cs#L1328> This method does not check for CRLF characters in the header value. This means that any headers added to a refit request are vulnerable to CRLF-injection. In general, CRLF-injection into a HTTP header (when using HTTP/1.1) means that one can inject additional HTTP headers or smuggle whole HTTP requests. ### PoC The below example code creates a console app that takes one command line variable (a bearer token) and then makes a request to some status page with the provided token inserted in the "Authorization" header: ```c# using Refit; internal class Program { private static void Main(string[] args) { // Usage: dotnet run <bearer token> string token = args[0]; var service = RestService.For<IStatusApi>("http://insert.some.site.here"); string response = service.GetStatus(token).Result; Console.WriteLine($"Response: {response}"); } public interface IStatusApi { [Get("/status")] Task<string> GetStatus([Authorize("Bearer")] string token); } } ``` This application is now vulnerable to CRLF-injection, and can thus be abused to for ex


Mitigations:

Architectural layers (MAESTRO):