Http Request Smuggling in Aspnet
How Http Request Smuggling Manifests in Aspnet
Http Request Smuggling in Aspnet applications often exploits the framework's handling of chunked transfer encoding and content-length headers. Unlike generic HTTP servers, Aspnet's pipeline processes requests through specific middleware that can be manipulated by carefully crafted requests.
The most common Aspnet-specific smuggling pattern involves Aspnet Core's Kestrel server and its handling of chunked encoding. Consider this attack vector:
POST /api/data HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 6
Transfer-Encoding: chunked
0
GET /admin HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 25
{ "admin": "true" }When this request hits an Aspnet Core application behind a reverse proxy that doesn't properly normalize headers, Kestrel may process the chunked data while the proxy only sees the initial Content-Length. This creates a scenario where the proxy forwards the second request to another service, effectively smuggling it through the Aspnet application.
Aspnet Web Forms applications are vulnerable to a different variant involving the aspNetHidden fields and view state manipulation. Attackers can craft requests that exploit the way Aspnet processes form data and view state serialization:
POST /VulnerablePage.aspx HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 300
Transfer-Encoding: chunked
1a; ignore-stuff-here
name=normalvalue&
0
GET /admin HTTP/1.1
Host: example.com
Content-Length: 0
Connection: closeThe key Aspnet-specific vulnerability here is that the framework's request processing pipeline doesn't always validate the consistency between Content-Length and Transfer-Encoding headers when they're both present. This allows attackers to create ambiguous requests that different components in the request chain interpret differently.
Aspnet-Specific Detection
Detecting Http Request Smuggling in Aspnet requires understanding how the framework processes requests at the middleware level. The first step is examining your Aspnet application's request pipeline configuration.
In Aspnet Core, check your Program.cs or Startup.cs for middleware ordering. The UseHttpsRedirection and UseStaticFiles middleware can create vulnerabilities if not configured properly:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Vulnerable ordering - can allow smuggling through static file middleware
app.UseHttpsRedirection();
app.UseStaticFiles(); // This can process requests before security checks
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});For detection, middleBrick's black-box scanning approach is particularly effective for Aspnet applications because it tests the actual runtime behavior without requiring source code access. The scanner sends crafted requests that test Aspnet's specific request processing:
$ middlebrick scan https://yourapi.com --target aspnet
Scan started: https://yourapi.com
Testing Aspnet-specific smuggling patterns...
✓ Chunked encoding validation
✓ Content-Length/Transfer-Encoding consistency
✓ View state manipulation
✓ Middleware ordering validation
Security Score: B (85/100)
Findings:
⚠️ Medium - Inconsistent header processing detected
Recommendation: Normalize headers in reverse proxyAdditional detection involves examining IIS/W3SVC logs for unusual request patterns. Aspnet applications behind IIS may show smuggling attempts through:
- Multiple requests with identical timestamps but different content
- Requests with both Content-Length and Transfer-Encoding headers
- Chunked encoding requests with suspicious chunk sizes
For Aspnet Web Forms applications, monitor for requests with malformed view state or unexpected form field combinations that could indicate smuggling attempts.
Aspnet-Specific Remediation
Remediating Http Request Smuggling in Aspnet applications requires a layered approach that addresses both framework-level and infrastructure-level vulnerabilities.
For Aspnet Core applications, the primary remediation is implementing strict header validation middleware. Here's a specific implementation:
public class RequestNormalizationMiddleware
{
private readonly RequestDelegate _next;
public RequestNormalizationMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
// Remove conflicting headers
if (context.Request.Headers.ContainsKey("Transfer-Encoding") &&
context.Request.Headers.ContainsKey("Content-Length"))
{
context.Request.Headers.Remove("Content-Length");
}
// Validate chunked encoding format
if (context.Request.Headers.ContainsKey("Transfer-Encoding"))
{
var encoding = context.Request.Headers["Transfer-Encoding"].ToString();
if (encoding != "chunked" && !encoding.Contains(", chunked"))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsync("Invalid Transfer-Encoding");
return;
}
}
await _next(context);
}
}Register this middleware early in your pipeline:
app.UseMiddleware<RequestNormalizationMiddleware>();
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});For Aspnet Web Forms applications running on IIS, configure request filtering at the server level:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
<headers>
<remove header="Transfer-Encoding" />
<remove header="Content-Length" />
</headers>
</requestFiltering>
</security>
</system.webServer>Another critical Aspnet-specific remediation is configuring the reverse proxy to properly handle chunked encoding. If using Nginx in front of Aspnet Core:
location / {
proxy_pass http://aspnet_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
// Critical: disable chunked transfer encoding
proxy_http_version 1.1;
chunked_transfer_encoding off;
// Force content-length calculation
proxy_buffering on;
proxy_request_buffering on;
}For comprehensive protection, integrate middleBrick's continuous monitoring into your deployment pipeline. The Pro plan's CI/CD integration can automatically scan staging APIs before production deployment:
name: API Security Scan
on: [pull_request]
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run middleBrick Scan
run: |
npm install -g middlebrick
middlebrick scan https://staging.yourapp.com --fail-below B
continue-on-error: falseThis ensures that any Http Request Smuggling vulnerabilities introduced in new code are caught before reaching production.