Claude skill HTTP desync security — SA-SKL-DESYNC: request smuggling, TE.TE obfuscation, pipeline injection, CRLF header injection
MCP skill backends deployed behind a reverse proxy inherit the HTTP request desynchronization attack surface. HTTP desync vulnerabilities arise from ambiguity in how different components of the request pipeline parse the same byte stream — specifically, disagreements about where one HTTP request ends and the next one begins. When the reverse proxy and the origin server disagree, an attacker can craft a request that causes the suffix of their own request to be prepended to the beginning of a subsequent user's request, hijacking that user's session, injecting headers into their request, or poisoning shared caches. SA-SKL-DESYNC covers four desync patterns that appear in MCP skill deployments: CL.TE smuggling via Content-Length/Transfer-Encoding conflict, TE.TE obfuscation via malformed Transfer-Encoding values, HTTP/1.1 keep-alive pipeline injection, and CRLF injection via proxy-forwarded headers.
HTTP request smuggling was first documented in 2005 and was dramatically re-elevated in 2019 by James Kettle's research at PortSwigger, which demonstrated that the attack was practical against real-world production infrastructure. The root cause has not changed in twenty years: HTTP/1.1 provides two mechanisms for specifying request body length (Content-Length and Transfer-Encoding: chunked), and when multiple components in a request pipeline interpret these headers differently, body boundaries become ambiguous. MCP skill deployments are particularly susceptible because they typically involve a managed reverse proxy (Nginx, Caddy, AWS ALB, Cloudflare) in front of a Node.js Express backend — two components with independent HTTP parsing logic that may disagree on body boundaries under adversarial inputs.
SA-SKL-DESYNC-001: Content-Length vs Transfer-Encoding conflict — CL.TE request smuggling hijacks victim requests
The CL.TE (Content-Length/Transfer-Encoding) variant of request smuggling occurs when the reverse proxy uses Content-Length to determine the request body length, while the origin server prefers Transfer-Encoding: chunked when both headers are present. The attacker sends a single request where the body, as interpreted by the proxy using Content-Length, contains a complete HTTP request prefix. The proxy forwards the entire thing to the origin as one request body. The origin, using the chunked encoding terminator (0\r\n\r\n) to find the end of the body, processes the first request and leaves the attacker-crafted suffix sitting at the head of the connection buffer. When the next legitimate user's request arrives, it is prepended with the attacker's suffix — effectively injecting headers, hijacking the session cookie, or routing the request to a different endpoint:
// CONTEXT: Nginx (proxy) + Node.js Express (origin)
// Nginx is configured to use HTTP/1.1 keep-alive to the origin
// Nginx forwards both Content-Length and Transfer-Encoding headers by default
// THE ATTACK REQUEST (sent directly to Nginx):
// POST /api/audits HTTP/1.1
// Host: skillaudit.dev
// Content-Length: 76 <-- Nginx uses this: reads 76 bytes of body, forwards all
// Transfer-Encoding: chunked <-- Node.js uses this: reads until "0\r\n\r\n" terminator
//
// 0\r\n <-- Node.js sees chunked body of size 0 (end of body)
// \r\n <-- Node.js ends first request here; 50 bytes remain in buffer
// GET /admin HTTP/1.1\r\n <-- These 50 bytes are the START of the next request
// X-Injected-Header: evil\r\n
// \r\n
//
// Nginx: one request with 76-byte body, forwards to origin.
// Node.js: processes first request (empty chunked body), leaves the GET /admin prefix
// at the head of the TCP connection buffer.
// Next legitimate user's request arrives: "GET /api/me HTTP/1.1\r\nCookie: session=VICTIM\r\n\r\n"
// Node.js HTTP parser sees: "GET /admin HTTP/1.1\r\nX-Injected-Header: evil\r\nGET /api/me HTTP/1.1\r\nCookie: session=VICTIM\r\n\r\n"
// The injected prefix rides in front of the victim's request, stealing their session cookie
// or routing the request to /admin with the victim's credentials
// VULNERABLE: Express application does not reject requests with conflicting headers
import express from 'express';
const app = express();
// No validation of incoming header combinations
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Express (via Node.js http module) will process Transfer-Encoding: chunked
// if both CL and TE are present, following Node.js's parser priority
// SECURE OPTION 1: Use HTTP/2 end-to-end between proxy and origin
// HTTP/2 uses a single framing protocol with explicit stream boundaries —
// there is no Content-Length vs Transfer-Encoding ambiguity at the protocol level
// In Nginx:
// upstream skillaudit_backend {
// server 127.0.0.1:3000;
// keepalive 32;
// }
// server {
// listen 443 ssl http2;
// location / {
// grpc_pass grpc://skillaudit_backend;
// # or: proxy_pass http://skillaudit_backend; with http2 upstream
// }
// }
// SECURE OPTION 2: reject requests with both Content-Length and Transfer-Encoding
// Add early validation middleware before any body parsing
import http from 'http';
function rejectAmbiguousTransferMiddleware(
req: express.Request,
res: express.Response,
next: express.NextFunction
): void {
const hasContentLength = 'content-length' in req.headers;
const hasTransferEncoding = 'transfer-encoding' in req.headers;
if (hasContentLength && hasTransferEncoding) {
// RFC 7230 section 3.3.3: If both are present, the server MUST reject the request
// or strip Content-Length and use Transfer-Encoding
res.status(400).json({
error: 'Ambiguous request: both Content-Length and Transfer-Encoding headers present',
});
return;
}
next();
}
// SECURE OPTION 3: configure Nginx to strip Transfer-Encoding before forwarding
// nginx.conf:
// proxy_set_header Transfer-Encoding ""; # strip TE, force CL-based parsing
// proxy_http_version 1.1; # keep-alive but CL-only on upstream side
// proxy_set_header Connection ""; # normalize connection header
// Apply as first middleware, before any body parsing
app.use(rejectAmbiguousTransferMiddleware);
app.use(express.json());
app.post('/api/audits', authenticate, async (req, res) => {
// Handler only reached if headers are unambiguous
const audit = await db.createAudit(req.body, req.session.userId);
res.json(audit);
});
HTTP request smuggling is a multi-request, multi-user attack: Unlike most web vulnerabilities, HTTP request smuggling affects requests from other users, not just the attacker's own requests. A single crafted request can poison the connection buffer such that the next 10, 100, or 1000 requests on that keep-alive connection are prefixed with attacker-controlled bytes. In a production system handling thousands of requests per minute, the attacker has a high probability of hitting an authenticated user's session within seconds of sending the poison request. The attack is also difficult to detect after the fact because the attack request itself may look innocuous in access logs, and the victim's request appears to have been sent to the wrong endpoint by the victim themselves.
Content-Length and Transfer-Encoding headers to Node.js origin; proxy parses by CL while Node.js parses by chunked TE; attacker's body suffix is left in the connection buffer and prepended to the next user's request, hijacking their session or injecting privilege-escalating headers. Fix: use HTTP/2 end-to-end; or add early middleware that returns 400 for requests with both CL and TE headers; or configure proxy to strip Transfer-Encoding before forwarding. Detection: Express server behind Nginx/Caddy without CL+TE rejection middleware and without HTTP/2 upstream → HIGH.SA-SKL-DESYNC-002: TE.TE obfuscation — unknown Transfer-Encoding extensions disagree at proxy and origin
The TE.TE variant of request smuggling exploits the fact that both proxy and origin parse the Transfer-Encoding header, but they may respond differently to unknown or malformed TE values. HTTP/1.1 specifies that an HTTP implementation encountering an unknown transfer encoding must either reject the request or fall back to parsing by Content-Length. When proxy and origin make different fallback decisions for the same malformed TE value, the attack surface is equivalent to CL.TE smuggling. A common example is Transfer-Encoding: chunked,identity or Transfer-Encoding:\x20chunked (a space-prefixed value that some parsers normalize while others reject). The attacker finds the specific obfuscation technique that causes the proxy to strip the malformed TE header (falling back to CL) while the origin accepts the chunked encoding:
// VULNERABLE: Express origin accepts malformed Transfer-Encoding variants
// that the reverse proxy strips or normalizes differently
// Example attack request with obfuscated Transfer-Encoding:
// POST /api/scan HTTP/1.1
// Host: skillaudit.dev
// Content-Type: application/json
// Content-Length: 65
// Transfer-Encoding: chunked, x-unknown <-- Nginx strips unknown extensions → falls back to CL=65
// <-- Node.js http module normalizes to 'chunked' → parses chunked
//
// 0\r\n <-- Node.js: end of chunked body (empty)
// \r\n <-- 42 bytes remain in buffer
// GET /internal HTTP/1.1\r\n
// X-Admin-Override: true\r\n
// \r\n
//
// Nginx interprets: 65 bytes of JSON body, all consumed, request ends cleanly.
// Node.js interprets: chunked body ending at "0\r\n\r\n", leaves 42-byte prefix
// in the TCP connection buffer for the next request.
// Other TE obfuscation variants that probe for proxy/origin disagreement:
// Transfer-Encoding: xchunked (some legacy parsers accept 'xchunked')
// Transfer-Encoding:\tchunked (tab character before 'chunked')
// Transfer-Encoding: chunked\r (carriage return in header value)
// Transfer-Encoding[0x0b]: chunked (vertical tab as header name separator)
// X-Transfer-Encoding: chunked (alternate header name accepted by some servers)
// Transfer-Encoding: identity\r\nTransfer-Encoding: chunked (TE header injection)
// VULNERABLE: no Transfer-Encoding value sanitization
import express from 'express';
const app = express();
app.use(express.json()); // parses body — but doesn't validate the TE header value
app.post('/api/scan', authenticate, async (req, res) => {
// request body boundaries determined by whatever Node.js http module decides
// about the potentially malformed Transfer-Encoding header value
const result = await runScan(req.body);
res.json(result);
});
// SECURE: add middleware that rejects any Transfer-Encoding value other than exactly 'chunked'
function validateTransferEncoding(
req: express.Request,
res: express.Response,
next: express.NextFunction
): void {
const te = req.headers['transfer-encoding'];
if (te === undefined) {
return next(); // No TE header: Content-Length only, unambiguous
}
// Normalize and check: only the exact string 'chunked' is acceptable
// Reject comma-delimited values, values with extra whitespace, or unknown encodings
const normalized = te.trim().toLowerCase();
if (normalized !== 'chunked') {
res.status(400).json({
error: `Unsupported or ambiguous Transfer-Encoding value: ${JSON.stringify(te)}`,
});
return;
}
// Reject if both TE: chunked AND Content-Length are present (CL.TE ambiguity)
if ('content-length' in req.headers) {
res.status(400).json({
error: 'Conflicting Content-Length and Transfer-Encoding: chunked headers',
});
return;
}
next();
}
// Also configure Nginx to block unknown TE values before they reach the origin:
// proxy_set_header Transfer-Encoding $http_transfer_encoding;
// # In Nginx, use a map to whitelist only 'chunked':
// map $http_transfer_encoding $valid_te {
// default 0;
// "" 1;
// "chunked" 1;
// }
// if ($valid_te = 0) { return 400; }
app.use(validateTransferEncoding);
app.use(express.json());
Fuzz the Transfer-Encoding header to find proxy/origin disagreements in your specific stack: The specific TE obfuscation technique that exploits a given proxy/origin pair depends on the exact parser versions involved. Nginx 1.21+ rejects most obfuscated TE values, but older Nginx versions and many CDNs do not. The safe defense is to enforce strict validation at the origin — any TE value that is not exactly the string chunked (case-insensitive, no extra whitespace, no comma-delimited extensions) must be rejected with 400. This is stricter than the RFC requires but completely eliminates the TE.TE attack surface.
Transfer-Encoding header values that the reverse proxy strips or normalizes differently; proxy falls back to Content-Length while origin parses chunked, leaving attacker-controlled prefix in connection buffer for the next request. Fix: add middleware rejecting any TE value other than exactly chunked; reject any request with both CL and TE headers; configure Nginx map block to block non-standard TE at the proxy layer. Detection: Express server without TE header validation middleware and not on HTTP/2 upstream → HIGH.SA-SKL-DESYNC-003: HTTP/1.1 keep-alive pipeline injection — attacker response body prefixes next pipelined request
HTTP/1.1 pipelining allows a client to send multiple requests on a single TCP connection without waiting for each response. The server processes them in order and writes responses sequentially. The desync opportunity arises when a response body is not properly delimited — specifically when a response omits Content-Length and uses a close-delimited body, but the connection is kept alive. If the response body happens to contain a byte sequence that looks like a valid HTTP response followed by a new HTTP request, the client's HTTP parser may misinterpret the second part as a server-pushed request or as the response to a subsequent pipelined request, allowing the attacker to inject an arbitrary response for the next request the victim sends on that connection. While HTTP/1.1 pipelining is rare in modern browsers, it is common on internal proxy-to-origin connections and in programmatic API clients:
// VULNERABLE: HTTP/1.1 pipelining on internal proxy-to-origin connection
// without strict response body delimitation
// Nginx → Node.js using keep-alive connection with pipelining enabled:
// proxy_http_version 1.1;
// proxy_set_header Connection ""; # keep-alive (default)
// (pipelining implicitly enabled by HTTP/1.1 keep-alive)
// In Express, if a response handler omits Content-Length or ends the response
// with data that could confuse a downstream parser:
app.get('/api/status', (req, res) => {
// If the response body is controlled by user input and contains CRLF sequences,
// a crafted body could look like it ends the response and starts a new one
const statusMessage = req.query.message as string; // USER CONTROLLED
res.set('Content-Type', 'text/plain');
// MISSING: Content-Length header — body is close-delimited
// If statusMessage contains "HTTP/1.1 200 OK\r\n...\r\n\r\nmalicious-body",
// a client parsing HTTP responses may interpret the embedded HTTP as a second response
res.end(statusMessage);
});
// More realistic scenario: response body includes user-controlled data
// that an internal monitoring client parses, and the body is forwarded
// through a pipeline on a reused connection:
app.get('/api/audit-report', async (req, res) => {
const report = await db.getReport(req.query.id as string);
// report.rawOutput is attacker-controlled (came from an analyzed repo)
// If Node.js HTTP layer does not add Content-Length, response length is ambiguous
res.json({ output: report.rawOutput }); // express json() does set Content-Length
// But older code using res.write() + res.end() without Content-Length does not
});
// SECURE: disable HTTP/1.1 pipelining on internal proxy-to-origin connections
// Prefer HTTP/2 for all internal service communication — HTTP/2 uses multiplexed
// streams with explicit frame boundaries, making pipelining-based desync impossible
// Nginx configuration to prevent pipelining on upstream connections:
// upstream skillaudit_backend {
// server 127.0.0.1:3000;
// keepalive 16;
// # Use HTTP/2 to backend if supported:
// # keepalive_timeout 65;
// }
// proxy_http_version 1.1; # Required for keepalive
// proxy_set_header Connection ""; # Required for keepalive (removes "close")
// # To disable pipelining, use HTTP/1.0 on upstream (forces close per request):
// # proxy_http_version 1.0; # disables keep-alive AND pipelining to origin
// SECURE: always set explicit Content-Length in Express responses
// (Express does this automatically for res.json() and res.send() with string/buffer bodies)
// For streaming responses, use Transfer-Encoding: chunked with proper termination:
app.get('/api/audit-stream', async (req, res) => {
res.set('Content-Type', 'application/json');
res.set('Transfer-Encoding', 'chunked');
res.set('X-Content-Type-Options', 'nosniff');
for await (const chunk of auditStream(req.query.id as string)) {
res.write(JSON.stringify(chunk) + '\n');
}
res.end(); // Sends the "0\r\n\r\n" terminator — unambiguous end of stream
});
// SECURE: validate and sanitize user-controlled data before including in response body
// If the response body must include user-controlled text, ensure it is JSON-encoded
// (JSON encoding escapes CR and LF as \r and \n, preventing CRLF injection in the body)
function sanitizeForResponseBody(value: string): string {
// JSON.stringify already escapes \r and \n:
return JSON.stringify(value); // "user\r\nstring" → "\"user\\r\\nstring\""
}
Internal proxy-to-origin connections are higher risk than client-facing connections for pipelining attacks: Modern browsers have largely abandoned HTTP/1.1 pipelining due to head-of-line blocking. However, internal monitoring systems, health checkers, service mesh sidecars, and API gateways frequently use pipelining on keep-alive connections for performance. If your MCP skill's backend is accessed by any programmatic HTTP client (not just browsers), HTTP/1.1 pipelining on that connection is an active attack surface. Use HTTP/2 for all internal service-to-service communication.
res.json() or res.send(). Detection: Nginx proxy-to-Express on HTTP/1.1 keep-alive with responses including user-controlled report.rawOutput or similar fields → MEDIUM.SA-SKL-DESYNC-004: CRLF injection via proxy-forwarded header — attacker injects arbitrary response headers enabling privilege escalation
Many reverse proxies forward the client's IP address to the origin server via headers such as X-Forwarded-For, X-Real-IP, or CF-Connecting-IP. If these values are taken directly from the incoming request without sanitization, an attacker who can reach the proxy can inject a header value containing carriage-return and line-feed characters (\r\n). HTTP header parsing splits headers on \r\n, so a value like 1.2.3.4\r\nX-Admin: true in X-Forwarded-For causes the Node.js HTTP parser to see two separate headers: X-Forwarded-For: 1.2.3.4 and X-Admin: true. If the application uses req.headers['x-admin'] for authorization, the attacker has injected a privilege-escalating header through a path the developer did not anticipate:
// VULNERABLE: Express application uses X-Admin or X-Internal headers for authorization
// A CRLF injection in X-Forwarded-For causes the origin to see the injected headers
// Nginx forwards X-Forwarded-For from the client request unchanged:
// proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
// (default behavior — appends client IP to any existing XFF header)
// Application uses X-Admin header for privilege checks:
app.use((req, res, next) => {
// DANGEROUS: X-Admin could be injected via CRLF in X-Forwarded-For
if (req.headers['x-admin'] === 'true') {
req.isAdmin = true;
}
next();
});
app.delete('/api/users/:id', (req, res) => {
if (!req.isAdmin) return res.status(403).json({ error: 'Forbidden' });
// If attacker injects X-Admin: true via CRLF in X-Forwarded-For,
// this check passes and the attacker can delete any user
db.deleteUser(req.params.id);
res.json({ deleted: true });
});
// ATTACK REQUEST (sent to Nginx):
// GET /api/users/VICTIM_ID HTTP/1.1
// Host: skillaudit.dev
// X-Forwarded-For: 1.2.3.4\r\nX-Admin: true
// ^^^^^^^^^^^^^^^^^^^^
// Nginx appends "1.2.3.4\r\nX-Admin: true" to XFF without sanitizing CRLF.
// When Node.js http module parses the forwarded request, it sees:
// X-Forwarded-For: 1.2.3.4
// X-Admin: true
// (two separate headers — CRLF injection complete)
//
// Note: modern Nginx versions (1.19+) reject header values with CR or LF.
// But older Nginx versions, Caddy < 2.6, AWS ALB, and some CDNs do not.
// Always sanitize at the application layer regardless of proxy version.
// SECURE OPTION 1: Sanitize all forwarded headers before use
function sanitizeHeaderValue(value: string | string[] | undefined): string | undefined {
if (!value) return undefined;
const str = Array.isArray(value) ? value[0] : value;
// Strip any CR, LF, or CRLF sequences — these have no legitimate place in a header value
const sanitized = str.replace(/[\r\n]/g, '');
return sanitized || undefined;
}
// Apply sanitization when reading forwarded headers:
app.use((req, res, next) => {
// Sanitize IP-forwarding headers
const rawXFF = req.headers['x-forwarded-for'];
if (rawXFF) {
const sanitized = sanitizeHeaderValue(rawXFF);
if (!sanitized) {
delete req.headers['x-forwarded-for'];
} else {
req.headers['x-forwarded-for'] = sanitized;
}
}
// Also sanitize X-Real-IP, CF-Connecting-IP, etc.
for (const hdr of ['x-real-ip', 'cf-connecting-ip', 'x-client-ip', 'x-forwarded-host']) {
const val = req.headers[hdr];
if (val) {
const clean = sanitizeHeaderValue(val);
if (!clean) delete req.headers[hdr];
else req.headers[hdr] = clean;
}
}
next();
});
// SECURE OPTION 2: Configure Nginx/Caddy to sanitize forwarded headers
// Caddy 2.6+ Caddyfile:
// header_up X-Forwarded-For {remote_host} # only the remote IP, not client-provided
// header_up -X-Admin # strip any client-provided X-Admin header
//
// Nginx:
// proxy_set_header X-Forwarded-For $remote_addr; # Only the real remote IP
// proxy_set_header X-Admin ""; # Always clear privileged headers
// SECURE OPTION 3: Never use X-* headers for authorization
// Use session tokens, JWT claims, or database role lookups instead.
// Header-based privilege flags are inherently forgeable and should not gate security decisions.
function isAdminFromSession(req: express.Request): boolean {
return req.session.role === 'admin'; // role set during login from DB, not from headers
}
app.delete('/api/users/:id', (req, res) => {
if (!isAdminFromSession(req)) return res.status(403).json({ error: 'Forbidden' });
db.deleteUser(req.params.id);
res.json({ deleted: true });
});
Never use X-Admin, X-Internal, or similar custom headers as authorization signals, regardless of CRLF injection: Even without CRLF injection, any client that can reach your origin server directly (bypassing the proxy) can set any header to any value. Using an HTTP header as an authorization signal requires that you can guarantee the proxy strips that header from all incoming requests. This guarantee is fragile — it breaks if the proxy is misconfigured, if a new proxy is added in the chain, or if the origin has an open port. Use session tokens and database role checks for authorization; treat all headers as untrusted input that must be validated.
req.headers['x-admin'] or similar headers for authorization; proxy forwards X-Forwarded-For values containing \r\n without sanitization; attacker crafts XFF value with \r\nX-Admin: true suffix; Node.js HTTP parser sees injected header; authorization check passes. Fix: sanitize all forwarded header values by stripping CR and LF characters before any application code reads them; configure proxy to set trusted headers from server state ($remote_addr) not from client input; never use custom X-* headers for authorization. Detection: req.headers['x-admin'] or req.headers['x-internal'] in authorization middleware without prior sanitization → HIGH.SkillAudit detection summary — SA-SKL-DESYNC
| Pattern ID | Severity | What SkillAudit flags | Fix |
|---|---|---|---|
| DESYNC-001 | HIGH | Express origin behind Nginx/Caddy proxy without middleware that rejects requests with both Content-Length and Transfer-Encoding: chunked; CL.TE ambiguity allows attacker to leave body suffix in connection buffer that prefixes next user's request |
Add early middleware rejecting requests with both CL and TE headers (400); configure proxy to strip TE before forwarding; prefer HTTP/2 end-to-end |
| DESYNC-002 | HIGH | Express origin accepts Transfer-Encoding values other than exactly chunked; proxy strips unknown TE extensions causing proxy/origin to disagree on body boundaries |
Middleware that rejects any TE value not exactly equal to chunked (case-insensitive, no extensions); Nginx map block to block non-standard TE at proxy |
| DESYNC-003 | MEDIUM | HTTP/1.1 pipelining on proxy-to-origin connection combined with responses including user-controlled data without strict Content-Length; attacker injects fake HTTP response prefix into response body | Use HTTP/2 for proxy-to-origin communication; set Nginx proxy proxy_http_version 1.0 to disable pipelining; always use res.json() or res.send() which set Content-Length automatically |
| DESYNC-004 | HIGH | Application reads req.headers['x-admin'] or similar privilege headers for authorization; proxy forwards client-supplied X-Forwarded-For without sanitizing CRLF sequences, enabling header injection |
Sanitize all forwarded header values by removing CR/LF; configure proxy to set trusted headers from $remote_addr; never use custom X-* headers for authorization |
Related patterns: SA-SKL-CORS2 advanced CORS security (proxy header forwarding and trust chain), SA-SKL-INFODISCLOSURE information disclosure (desync attacks often reveal internal request contents), SA-SKL-CSRF CSRF protection (session hijacking via smuggled requests), SA-SKL-SESS session security (session binding after request hijacking).
SkillAudit's SA-SKL-DESYNC detection analyzes MCP skill backend code for missing CL/TE validation middleware, non-standard Transfer-Encoding acceptance, response body delimitation gaps, and X-* header authorization patterns that CRLF injection can exploit. All four patterns are detected through static analysis of Express middleware configuration and proxy setup. See the SA-SKL attack surface reference for the complete vulnerability taxonomy.
Scan your Claude skill backend for HTTP desync vulnerabilities
SkillAudit detects CL.TE smuggling gaps, TE.TE obfuscation exposure, pipeline injection, and CRLF header injection across the full SA-SKL-DESYNC family in 60 seconds.
Get your free audit