HIGH http request smugglingbearer tokens

Http Request Smuggling with Bearer Tokens

How Http Request Smuggling Manifests in Bearer Tokens

Http Request Smuggling in Bearer Tokens contexts creates unique attack vectors that exploit the token-based authentication system. Unlike traditional session-based attacks, Bearer Token smuggling targets the way authentication tokens are transmitted and processed across different components of your API infrastructure.

The most common manifestation occurs when multiple servers or proxies handle the same request with different interpretations of Content-Length and Transfer-Encoding headers. Consider a scenario where a frontend proxy strips or modifies Authorization headers while a backend server expects them:

POST /api/resource HTTP/1.1
Host: api.example.com
Content-Length: 25
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

GET /api/secret HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

In this example, the frontend might process only the first line as a single request, while the backend interprets it as two separate requests. The second request gets processed with the stolen Bearer token, allowing attackers to access protected resources without proper authentication.

Another Bearer Tokens-specific pattern involves token injection through malformed multipart requests. When APIs accept file uploads with Bearer token authentication, attackers can craft requests that confuse the parser:

POST /upload HTTP/1.1
Host: api.example.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary
Content-Length: 1234
Authorization: Bearer valid.token.here

------WebKitFormBoundary
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

------WebKitFormBoundary
Content-Disposition: form-data; name="malicious"

GET /admin HTTP/1.1
Authorization: Bearer stolen.token.here
Content-Length: 0

------WebKitFormBoundary--

The backend server might process the second request as valid, using the attacker's stolen Bearer token to access administrative endpoints.

CRLF injection combined with Bearer tokens creates another smuggling vector. Attackers can inject newline characters to split headers:

POST /api/data HTTP/1.1
Host: target.com
Content-Type: application/json
Content-Length: 50
Authorization: Bearer legitimate-token GET /admin HTTP/1.1 Authorization: Bearer stolen-token

When the server processes this, it might treat the second request as a legitimate separate request, executing it with the attacker's credentials.

Bearer Tokens-Specific Detection

Detecting Http Request Smuggling in Bearer Tokens systems requires specialized testing that accounts for token-based authentication flows. Traditional smuggling detection tools often miss these specific patterns because they don't properly handle Bearer token authentication mechanisms.

middleBrick's Bearer Tokens-specific scanning identifies smuggling vulnerabilities by testing authentication token handling across your entire API surface. The scanner sends crafted requests with multiple Authorization headers and malformed content encodings to detect inconsistencies in how different components process Bearer tokens.

Key detection patterns include:

  • Multiple Authorization headers with different Bearer tokens to test which one gets processed
  • Malformed Content-Length headers combined with Transfer-Encoding to trigger parser conflicts
  • CRLF injection attempts in Authorization header values
  • Multipart form data with embedded HTTP requests containing Bearer tokens
  • Chunked transfer encoding with embedded requests using stolen tokens

The scanner analyzes responses for indicators of successful smuggling, such as unexpected 200 OK responses to unauthorized requests, or processing of requests that shouldn't be valid based on the original payload.

Manual testing can be performed using tools like curl or Postman with specific patterns:

# Test multiple Authorization headers
curl -X POST https://api.example.com/endpoint \ -H "Content-Type: application/json" \ -H "Authorization: Bearer valid.token.1" \ -H "Authorization: Bearer stolen.token.2" \ -d '{"test":"data"}'

Monitor which token gets processed by checking response data or using different payloads for each token to track execution flow.

Another detection technique involves sending requests with conflicting Content-Length and Transfer-Encoding headers:

POST /api/upload HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 10
Transfer-Encoding: chunked
Authorization: Bearer legitimate-token

0 GET /admin HTTP/1.1 Authorization: Bearer stolen-token

If the server processes the second request, you've identified a smuggling vulnerability.

Bearer Tokens-Specific Remediation

Remediating Http Request Smuggling in Bearer Tokens systems requires a defense-in-depth approach that addresses both the smuggling vectors and the token handling mechanisms. The primary mitigation is ensuring consistent request parsing across your entire infrastructure stack.

First, standardize header processing across all components. Implement strict header validation that rejects requests with multiple Authorization headers or malformed authentication tokens:

// Node.js Express middleware for strict Authorization header validation
app.use((req, res, next) => {
const authHeader = req.get('Authorization');
return res.status(401).json({error: 'Missing Bearer token'});
}
if (req.rawHeaders.filter(h => h === 'Authorization').length > 1) {
return res.status(400).json({error: 'Multiple Authorization headers not allowed'});
}
next();
});

Implement strict Content-Length and Transfer-Encoding validation to prevent parser confusion:

// Strict request body validation middleware
app.use((req, res, next) => {
const contentLength = parseInt(req.get('Content-Length'));
const transferEncoding = req.get('Transfer-Encoding');

if (transferEncoding && transferEncoding.toLowerCase() !== 'chunked') {
return res.status(400).json({error: 'Invalid Transfer-Encoding'});
}

// Validate Content-Length matches actual body size
if (req.readable && !transferEncoding) {
const body = [];
req.on('data', chunk => body.push(chunk));
req.on('end', () => {
const totalLength = Buffer.concat(body).length;
if (totalLength !== contentLength) {
return res.status(400).json({error: 'Content-Length mismatch'});
}
next();
});
} else {
next();
}
});

Use a single, trusted reverse proxy that handles all request parsing before reaching your application servers. This eliminates inconsistencies between different parsing implementations:

# nginx configuration with strict request validation
server {
listen 443 ssl;
server_name api.example.com;

# Reject requests with multiple Authorization headers
if ($http_authorization_count > 1) {
return 400;
}

# Strict Content-Length validation
if ($request_body_length != $http_content_length) {
return 411;
}
proxy_pass http://backend;
proxy_set_header Authorization $http_authorization;
}
}

Implement token binding to prevent stolen token usage. Bind Bearer tokens to specific client characteristics:

// Token binding implementation
function validateTokenBinding(token, req) {
const tokenData = jwt.verify(token, process.env.JWT_SECRET);
const userAgent = req.get('User-Agent');

// Check if token was issued for this client
throw new Error('Token binding validation failed');
}
}

Regularly rotate API keys and Bearer tokens to minimize the window of opportunity for attackers who might have obtained tokens through smuggling attacks. Implement short expiration times and immediate revocation capabilities.

Monitor for unusual authentication patterns that might indicate successful smuggling attacks, such as multiple token uses from different IP addresses or unexpected access patterns to protected resources.

Frequently Asked Questions

How can I test my Bearer Tokens API for Http Request Smuggling vulnerabilities?

Use middleBrick's automated scanning to test your Bearer Tokens endpoints for smuggling vulnerabilities. The scanner sends crafted requests with multiple Authorization headers, malformed Content-Length values, and embedded HTTP requests to detect inconsistencies in how your API processes Bearer tokens. For manual testing, use curl to send requests with conflicting headers and monitor which tokens get processed by checking response data or using unique payloads for each token.

What's the difference between Http Request Smuggling and HTTP Request Splitting in Bearer Tokens contexts?

HTTP Request Splitting typically involves CRLF injection to create separate requests within a single payload, while Request Smuggling exploits inconsistencies in how different servers parse Content-Length and Transfer-Encoding headers. In Bearer Tokens contexts, Splitting might involve injecting newline characters in Authorization headers, whereas Smuggling involves crafting requests that confuse the parser about where one request ends and another begins, often using malformed multipart form data or chunked encoding with embedded requests containing stolen tokens.