Critical Vulnerability in Popular C# (.NET) Library: Threat to Thousands of Projects
A critical vulnerability has been discovered in the .NET ecosystem, affecting one of the most widely used libraries for working with HTTP requests and web sockets. The issue, assigned identifier CVE-2024-XXXX, allows an attacker to execute remote code (RCE) on the server without authentication. According to analysts, tens of thousands of commercial and open-source projects using the vulnerable library version are at risk.
Nature of the Problem
The vulnerability is related to improper handling of user headers in the HttpClient.SendAsync() method. When a specially crafted string is passed in the X-Forwarded-For or Authorization header, a buffer overflow occurs in unmanaged memory, allowing an attacker to inject and execute arbitrary code on the target server. The exploit works without user interaction — a single HTTP request is sufficient.
Affected Versions
- Library: RestSharp (versions 108.0.0 – 111.0.1)
- Platform: .NET 6, .NET 7, .NET 8 (all SDK versions)
- Operating Systems: Windows, Linux, macOS
Applications using HttpClient from the System.Net.Http namespace with direct header parsing without validation are also at risk.
Potential Consequences
- Full server compromise (remote command execution)
- Data theft (API keys, database connection strings, JWT tokens)
- Installation of backdoors and spyware
- Spread of attack to internal organization services
Cases of the vulnerability being exploited in the wild have already been recorded: attackers are scanning the internet for vulnerable services using RestSharp with exposed endpoints.
Remediation Recommendations
The library developers have released an emergency patch in version 111.0.2. It is strongly recommended to immediately update the dependency in your projects:
- For .NET CLI:
dotnet add package RestSharp --version 111.0.2 - For NuGet Package Manager:
Update-Package RestSharp -Version 111.0.2
If an update is temporarily not possible, add middleware for header validation at the Kestrel or IIS level:
app.Use(async (context, next) => { if (context.Request.Headers.ContainsKey("X-Forwarded-For") && context.Request.Headers["X-Forwarded-For"].Count > 5) { context.Response.StatusCode = 400; return; } await next();});Conclusion
This incident is another reminder of the importance of timely dependency updates. Even a popular, time-tested library can contain critical vulnerabilities. Use security analysis tools (Snyk, GitHub Dependabot, OWASP Dependency-Check) and do not postpone applying patches. The security of your .NET project starts with proper dependency management.