Skip to main content
Security guideReviewed

HTTP request smuggling: when the proxy and the server disagree about where a request ends

HTTP request smuggling, also called an HTTP desync attack, happens when a front end such as a reverse proxy, CDN or load balancer and the server behind it read the same bytes and disagree about where one request ends.

This guide explains why that matters, what the HTTP standards require of each component, how HTTP/2 downgrading changes the picture and which fixes close the gap. The parser trace lab below runs on your own machine, on 127.0.0.1 only, and shows the disagreement in a few lines of output.

Parser trace lab with differential tests and a verification checklist

An illustration written for this page: a tiny front end and back end in Node.js, built with its built-in modules only, that disagree about where a request ends; the corrected pair that agrees; a trace of how each side framed the same bytes; a regression test; the output recorded when it ran on Node.js v26.0.0; and a verification checklist for normalisation, connection reuse and duplicate header handling. Run it on your own machine only, where everything listens on 127.0.0.1.

http-request-smuggling.txt

HTTP REQUEST SMUGGLING PARSER TRACE LAB
Version 1.0. An illustration written for this page: teaching code, not a product.


WHAT IT SHOWS

A front end (proxy.js) and a back end (back-end.js) read the same bytes with two different HTTP/1.1 parsers.

- The mismatched pair: each parser is lenient in a different way. The trace shows them disagree about where a request ends, and shows the leftover bytes turning up at the start of the next request.
- The corrected pair: both parsers refuse ambiguous framing with 400 and close the connection, and the front end forwards each request it accepts with one Content-Length that matches the body. The trace shows them agree.
- A regression test runs every probe through a pair. It fails on the mismatched pair and passes on the corrected pair.


BEFORE YOU RUN IT

- Run it on your own machine. Every server listens on 127.0.0.1, on a port the operating system picks, and every client connects to 127.0.0.1 only.
- Use it to learn, and to check a front end and back end you own, running locally.
- Do not send these probes, or any ambiguous request, to a system you do not own or to shared production infrastructure. Where a front end shares back-end connections between visitors, leftover bytes land on whoever's request comes next, so a probe can affect other people's traffic.
- The parsers are teaching code. Do not put them in front of real traffic.


WHAT YOU NEED

Node.js and its built-in modules (net, test and assert). Nothing to install.
The output further down was recorded with Node.js v26.0.0 on macOS.
Save the nine files below into one empty folder, with the file names shown.


COMMANDS

Trace one probe through one pair:
  node run-trace.js mismatched space-before-colon
  node run-trace.js corrected space-before-colon

The same probe, with the front end opening a new back-end connection for every request:
  node run-trace.js mismatched space-before-colon no-reuse

Probe names: space-before-colon, two-different-lengths, length-and-chunked, repeated-equal-lengths, plain-chunked.

Regression test (on Windows, set the PAIR environment variable the way your shell does):
  PAIR=mismatched node --test --test-reporter=spec differential.test.js
  PAIR=corrected node --test --test-reporter=spec differential.test.js

Leave a pair running in one terminal and probe it from a second terminal:
  node serve-pair.js mismatched
  node send-probe.js 52831 space-before-colon
Use the front-end port that serve-pair.js prints. Stop serve-pair.js with Ctrl+C.


HOW TO READ THE BYTES

Under "client sent:" each carriage return and line feed is written out as \r\n, followed by a line break so the message stays readable. On "forwarded" lines the whole message sits on one line, with \r\n written out the same way.


==================== FILE 1 OF 9: framing.js ====================

'use strict'
// framing.js: decides where one HTTP/1.1 request ends in a stream of bytes.
// Text is handled as latin1, so each byte is one character.
// Teaching code for a loopback lab. Do not put it in front of real traffic.

const CRLF = '\r\n'
const STATUS_TEXT = { 200: 'OK', 400: 'Bad Request', 413: 'Content Too Large', 501: 'Not Implemented' }

// The mismatched pair: each side is lenient in a different way.
const LENIENT_FRONT_END = { label: 'front end', strict: false, trimNames: false, chunkedTest: 'exact', lengthPick: 'last' }
const LENIENT_BACK_END = { label: 'back end ', strict: false, trimNames: true, chunkedTest: 'contains', lengthPick: 'first' }

// The corrected pair: both strict. The front end may collapse repeated equal
// Content-Length values into one; the back end rejects any repetition.
const STRICT_FRONT_END = { label: 'front end', strict: true, collapseRepeatedLength: true }
const STRICT_BACK_END = { label: 'back end ', strict: true, collapseRepeatedLength: false }

function reject(code, reason) {
  return { status: 'error', code: code, reason: reason }
}

function splitHead(buffer) {
  const headEnd = buffer.indexOf(CRLF + CRLF)
  if (headEnd === -1) return null
  const lines = buffer.slice(0, headEnd).split(CRLF)
  return { requestLine: lines[0], fieldLines: lines.slice(1), bodyStart: headEnd + 4 }
}

function readFields(fieldLines, trimNames) {
  const fields = []
  for (const line of fieldLines) {
    const colon = line.indexOf(':')
    let name = line.slice(0, colon).toLowerCase()
    if (trimNames) name = name.trim()
    fields.push({ name: name, value: line.slice(colon + 1).trim() })
  }
  return fields
}

function valuesOf(fields, name) {
  const values = []
  for (const field of fields) {
    if (field.name === name) values.push(field.value)
  }
  return values
}

// Lenient: never rejects. Picks a framing using its own shortcuts.
function chooseLenientFraming(fieldLines, policy) {
  const fields = readFields(fieldLines, policy.trimNames)
  for (const value of valuesOf(fields, 'transfer-encoding')) {
    const lower = value.toLowerCase()
    const isChunked = policy.chunkedTest === 'exact' ? lower === 'chunked' : lower.includes('chunked')
    if (isChunked) return { kind: 'chunked', note: 'Transfer-Encoding: ' + value }
  }
  const lengths = valuesOf(fields, 'content-length')
  if (lengths.length === 0) return { kind: 'length', length: 0, note: 'no framing header' }
  const picked = policy.lengthPick === 'last' ? lengths[lengths.length - 1] : lengths[0]
  const note = 'Content-Length: ' + picked + ' (' + policy.lengthPick + ' of ' + lengths.length + ')'
  return { kind: 'length', length: Number(picked), note: note }
}

function findFieldLineProblem(line) {
  if (line.startsWith(' ') || line.startsWith('\t')) return 'field line starts with whitespace'
  if (line.includes('\r') || line.includes('\n')) return 'bare CR or LF in the header section'
  const colon = line.indexOf(':')
  if (colon < 1) return 'field line without a name and colon'
  const name = line.slice(0, colon)
  if (name.includes(' ') || name.includes('\t')) return 'whitespace between field name and colon'
  return ''
}

// Every value of a field, split on commas, trimmed and lowercased.
function listValues(fieldLines, name) {
  const values = []
  for (const field of readFields(fieldLines, false)) {
    if (field.name !== name) continue
    for (const part of field.value.split(',')) values.push(part.trim().toLowerCase())
  }
  return values
}

function chooseStrictChunked(codings) {
  if (codings[codings.length - 1] !== 'chunked') return reject(400, 'chunked is not the final transfer coding')
  let chunkedCount = 0
  for (const coding of codings) if (coding === 'chunked') chunkedCount += 1
  if (chunkedCount > 1) return reject(400, 'chunked applied more than once')
  if (codings.length > 1) return reject(501, 'transfer coding this lab does not implement')
  return { kind: 'chunked', note: 'Transfer-Encoding: chunked' }
}

function chooseStrictLength(lengths, policy) {
  for (const value of lengths) {
    if (!/^[0-9]+$/.test(value)) return reject(400, 'invalid Content-Length value')
    if (value.length > 15) return reject(413, 'Content-Length larger than this lab accepts')
  }
  if (new Set(lengths).size > 1) return reject(400, 'Content-Length values disagree')
  if (lengths.length > 1 && !policy.collapseRepeatedLength) return reject(400, 'repeated Content-Length')
  const note = 'Content-Length: ' + lengths[0] + (lengths.length > 1 ? ' (' + lengths.length + ' equal values collapsed)' : '')
  return { kind: 'length', length: Number(lengths[0]), note: note }
}

// Strict: rejects the ambiguous forms this lab knows about, before reading a body.
function checkStrictFraming(fieldLines, policy) {
  for (const line of fieldLines) {
    const problem = findFieldLineProblem(line)
    if (problem) return reject(400, problem)
  }
  const codings = listValues(fieldLines, 'transfer-encoding')
  const lengths = listValues(fieldLines, 'content-length')
  if (codings.length > 0 && lengths.length > 0) return reject(400, 'both Content-Length and Transfer-Encoding')
  if (codings.length > 0) return chooseStrictChunked(codings)
  if (lengths.length === 0) return { kind: 'length', length: 0, note: 'no framing header' }
  return chooseStrictLength(lengths, policy)
}

function readTrailer(buffer, position, body) {
  if (buffer.startsWith(CRLF, position)) return { status: 'ok', end: position + 2, body: body }
  const trailerEnd = buffer.indexOf(CRLF + CRLF, position)
  if (trailerEnd === -1) return { status: 'incomplete' }
  return { status: 'ok', end: trailerEnd + 4, body: body }
}

function readChunked(buffer, start) {
  let position = start
  let body = ''
  while (true) {
    const lineEnd = buffer.indexOf(CRLF, position)
    if (lineEnd === -1) return { status: 'incomplete' }
    const sizeText = buffer.slice(position, lineEnd).split(';')[0]
    if (!/^[0-9a-fA-F]{1,8}$/.test(sizeText)) return reject(400, 'invalid chunk size')
    const size = parseInt(sizeText, 16)
    position = lineEnd + 2
    if (size === 0) return readTrailer(buffer, position, body)
    if (buffer.length < position + size + 2) return { status: 'incomplete' }
    if (buffer.slice(position + size, position + size + 2) !== CRLF) return reject(400, 'chunk data not followed by CRLF')
    body += buffer.slice(position, position + size)
    position += size + 2
  }
}

function readBody(buffer, bodyStart, framing) {
  if (framing.kind === 'chunked') return readChunked(buffer, bodyStart)
  const end = bodyStart + framing.length
  if (buffer.length < end) return { status: 'incomplete' }
  return { status: 'ok', end: end, body: buffer.slice(bodyStart, end) }
}

// The one entry point: where does the first request in this buffer end?
function frameRequest(buffer, policy) {
  const head = splitHead(buffer)
  if (head === null) return { status: 'incomplete' }
  const framing = policy.strict ? checkStrictFraming(head.fieldLines, policy) : chooseLenientFraming(head.fieldLines, policy)
  if (framing.status === 'error') return framing
  const body = readBody(buffer, head.bodyStart, framing)
  if (body.status !== 'ok') return body
  return { status: 'ok', requestLine: head.requestLine, fieldLines: head.fieldLines, framing: framing, body: body.body, end: body.end }
}

function isFramingHeader(line) {
  const name = line.slice(0, line.indexOf(':')).trim().toLowerCase()
  return name === 'content-length' || name === 'transfer-encoding'
}

// Lenient: forwards the bytes as received. Strict: forwards one clean framing.
function buildForwardedBytes(buffer, message, policy) {
  if (!policy.strict) return buffer.slice(0, message.end)
  const lines = [message.requestLine]
  for (const line of message.fieldLines) if (!isFramingHeader(line)) lines.push(line)
  if (message.framing.note !== 'no framing header') lines.push('Content-Length: ' + message.body.length)
  return lines.join(CRLF) + CRLF + CRLF + message.body
}

function buildResponse(code, text, closeConnection) {
  const lines = ['HTTP/1.1 ' + code + ' ' + STATUS_TEXT[code], 'Content-Length: ' + text.length]
  if (closeConnection) lines.push('Connection: close')
  return lines.join(CRLF) + CRLF + CRLF + text
}

// Responses in this lab always carry Content-Length.
function frameResponse(buffer) {
  const head = splitHead(buffer)
  if (head === null) return { status: 'incomplete' }
  const lengths = valuesOf(readFields(head.fieldLines, true), 'content-length')
  const end = head.bodyStart + (lengths.length ? Number(lengths[0]) : 0)
  if (buffer.length < end) return { status: 'incomplete' }
  return { status: 'ok', statusLine: head.requestLine, raw: buffer.slice(0, end), end: end }
}

module.exports = {
  LENIENT_FRONT_END, LENIENT_BACK_END, STRICT_FRONT_END, STRICT_BACK_END,
  frameRequest, buildForwardedBytes, buildResponse, frameResponse, isFramingHeader,
}


==================== FILE 2 OF 9: back-end.js ====================

'use strict'
// back-end.js: an origin server that reads requests one after another
// from each connection the front end opens, and reports how it framed them.

const net = require('node:net')
const framing = require('./framing')

function handleBackEndData(state, socket, policy, trace) {
  while (true) {
    const result = framing.frameRequest(state.buffer, policy)
    if (result.status === 'incomplete') return
    if (result.status === 'error') {
      trace.add({ who: policy.label, kind: 'rejected', code: result.code, reason: result.reason })
      state.buffer = ''
      socket.end(framing.buildResponse(result.code, result.reason, true), 'latin1')
      return
    }
    state.buffer = state.buffer.slice(result.end)
    trace.add({ who: policy.label, kind: 'framed', requestLine: result.requestLine, note: result.framing.note, bodyLength: result.body.length })
    if (state.buffer.length > 0) trace.add({ who: policy.label, kind: 'leftover', text: state.buffer })
    socket.write(framing.buildResponse(200, 'back end framed: ' + result.requestLine, false), 'latin1')
  }
}

function startBackEnd(policy, trace) {
  const sockets = new Set()
  const server = net.createServer(function (socket) {
    sockets.add(socket)
    const state = { buffer: '' }
    socket.on('data', function (chunk) {
      state.buffer += chunk.toString('latin1')
      handleBackEndData(state, socket, policy, trace)
    })
    socket.on('end', function () {
      if (state.buffer.length > 0) trace.add({ who: policy.label, kind: 'unframed-at-close', text: state.buffer })
    })
    socket.on('error', function () {})
    socket.on('close', function () { sockets.delete(socket) })
  })
  return new Promise(function (resolve) {
    // Port 0 asks the operating system for a free ephemeral port on loopback only.
    server.listen(0, '127.0.0.1', function () {
      resolve({ port: server.address().port, stop: function () { stopServer(server, sockets) } })
    })
  })
}

function stopServer(server, sockets) {
  for (const socket of sockets) socket.destroy()
  server.close()
}

module.exports = { startBackEnd, stopServer }


==================== FILE 3 OF 9: proxy.js ====================

'use strict'
// proxy.js: a front end that frames each client request with its own parser,
// forwards it to the back end, and relays the back end's response.
// With reuseBackendConnection on, every client shares one back-end connection.

const net = require('node:net')
const framing = require('./framing')
const backEnd = require('./back-end')

function openBackEndLink(port, options, sockets) {
  const link = { socket: net.connect(port, '127.0.0.1'), buffer: '', waiting: [], open: true }
  sockets.add(link.socket)
  link.socket.on('data', function (chunk) {
    link.buffer += chunk.toString('latin1')
    relayResponses(link, options)
  })
  link.socket.on('end', function () { link.open = false })
  link.socket.on('error', function () { link.open = false })
  link.socket.on('close', function () { link.open = false })
  return link
}

function relayResponses(link, options) {
  while (true) {
    const response = framing.frameResponse(link.buffer)
    if (response.status !== 'ok') return
    link.buffer = link.buffer.slice(response.end)
    const client = link.waiting.shift()
    if (client && !client.destroyed) client.write(response.raw, 'latin1')
    if (!options.reuseBackendConnection) link.socket.end()
  }
}

function handleClientData(state, client, context) {
  const policy = context.policy
  while (!state.closed) {
    const result = framing.frameRequest(state.buffer, policy)
    if (result.status === 'incomplete') return
    if (result.status === 'error') {
      context.trace.add({ who: policy.label, kind: 'rejected', code: result.code, reason: result.reason })
      state.closed = true
      client.end(framing.buildResponse(result.code, result.reason, true), 'latin1')
      return
    }
    const forwarded = framing.buildForwardedBytes(state.buffer, result, policy)
    state.buffer = state.buffer.slice(result.end)
    context.trace.add({ who: policy.label, kind: 'framed', requestLine: result.requestLine, note: result.framing.note, bodyLength: result.body.length, forwarded: forwarded })
    const link = context.chooseLink()
    link.waiting.push(client)
    link.socket.write(forwarded, 'latin1')
  }
}

function startProxy(policy, backEndPort, options, trace) {
  const sockets = new Set()
  let sharedLink = null
  function chooseLink() {
    if (options.reuseBackendConnection && sharedLink && sharedLink.open) return sharedLink
    const link = openBackEndLink(backEndPort, options, sockets)
    if (options.reuseBackendConnection) sharedLink = link
    return link
  }
  const context = { policy: policy, trace: trace, chooseLink: chooseLink }
  const server = net.createServer(function (client) {
    sockets.add(client)
    const state = { buffer: '', closed: false }
    client.on('data', function (chunk) {
      state.buffer += chunk.toString('latin1')
      handleClientData(state, client, context)
    })
    client.on('error', function () {})
    client.on('close', function () { sockets.delete(client) })
  })
  return new Promise(function (resolve) {
    server.listen(0, '127.0.0.1', function () {
      resolve({ port: server.address().port, stop: function () { backEnd.stopServer(server, sockets) } })
    })
  })
}

module.exports = { startProxy }


==================== FILE 4 OF 9: probes.js ====================

'use strict'
// probes.js: inert test messages, each untidy in one way only.
// LEFTOVER is not a method or a request line. If a parser leaves it on a
// connection, it shows up as a visibly broken method on the next message.

const CRLF = '\r\n'

function message(lines, body) {
  return lines.join(CRLF) + CRLF + CRLF + body
}

const PROBES = [
  {
    name: 'space-before-colon',
    ambiguous: true,
    bytes: message(['POST /submit HTTP/1.1', 'Host: lab.test', 'Content-Length: 13', 'Transfer-Encoding : chunked'], '0' + CRLF + CRLF + 'LEFTOVER'),
  },
  {
    name: 'two-different-lengths',
    ambiguous: true,
    bytes: message(['POST /submit HTTP/1.1', 'Host: lab.test', 'Content-Length: 0', 'Content-Length: 8'], 'LEFTOVER'),
  },
  {
    name: 'length-and-chunked',
    ambiguous: true,
    bytes: message(['POST /submit HTTP/1.1', 'Host: lab.test', 'Content-Length: 5', 'Transfer-Encoding: chunked'], '0' + CRLF + CRLF),
  },
  {
    name: 'repeated-equal-lengths',
    ambiguous: false,
    bytes: message(['POST /submit HTTP/1.1', 'Host: lab.test', 'Content-Length: 8', 'Content-Length: 8'], 'lab-body'),
  },
  {
    name: 'plain-chunked',
    ambiguous: false,
    bytes: message(['POST /submit HTTP/1.1', 'Host: lab.test', 'Transfer-Encoding: chunked'], '8' + CRLF + 'lab-body' + CRLF + '0' + CRLF + CRLF),
  },
]

// Sent after every probe, so leftover bytes have a next message to land on.
const FOLLOW_UP = message(['GET /second HTTP/1.1', 'Host: lab.test'], '')

function findProbe(name) {
  for (const probe of PROBES) if (probe.name === name) return probe
  throw new Error('No probe named ' + name)
}

module.exports = { PROBES, FOLLOW_UP, findProbe }


==================== FILE 5 OF 9: harness.js ====================

'use strict'
// harness.js: starts a front end and a back end on loopback, sends one probe
// and the follow-up request, records how each side framed the bytes, then
// shuts everything down. Nothing here connects anywhere except 127.0.0.1.

const net = require('node:net')
const framing = require('./framing')
const backEnd = require('./back-end')
const proxy = require('./proxy')
const probes = require('./probes')

const PAIRS = {
  mismatched: { frontEnd: framing.LENIENT_FRONT_END, backEnd: framing.LENIENT_BACK_END },
  corrected: { frontEnd: framing.STRICT_FRONT_END, backEnd: framing.STRICT_BACK_END },
}

function pause(milliseconds) {
  return new Promise(function (resolve) { setTimeout(resolve, milliseconds) })
}

function openClient(port) {
  const socket = net.connect(port, '127.0.0.1')
  const client = { socket: socket, buffer: '', closed: false, onChange: function () {} }
  socket.on('data', function (chunk) { client.buffer += chunk.toString('latin1'); client.onChange() })
  socket.on('close', function () { client.closed = true; client.onChange() })
  socket.on('error', function () {})
  return client
}

// Resolves with the next full response, or null if the connection closes first.
function sendAndRead(client, bytes) {
  return new Promise(function (resolve) {
    const timer = setTimeout(function () { resolve(null) }, 1000)
    client.onChange = function () {
      const response = framing.frameResponse(client.buffer)
      if (response.status === 'ok') {
        client.buffer = client.buffer.slice(response.end)
        clearTimeout(timer)
        resolve(response)
      } else if (client.closed) {
        clearTimeout(timer)
        resolve(null)
      }
    }
    client.socket.write(bytes, 'latin1')
  })
}

function summarise(events, who) {
  const framed = []
  for (const event of events) {
    if (event.kind === 'framed' && event.who === who) framed.push(event.requestLine + ', body ' + event.bodyLength + ' bytes')
  }
  return framed
}

async function runProbe(pairName, probe, options) {
  const pair = PAIRS[pairName]
  const trace = { events: [], add: function (event) { trace.events.push(event) } }
  const server = await backEnd.startBackEnd(pair.backEnd, trace)
  const front = await proxy.startProxy(pair.frontEnd, server.port, options, trace)
  const first = openClient(front.port)
  const firstResponse = await sendAndRead(first, probe.bytes)
  await pause(50)
  const second = first.closed ? openClient(front.port) : first
  await sendAndRead(second, probes.FOLLOW_UP)
  await pause(50)
  const firstConnectionClosed = first.closed
  first.socket.destroy()
  second.socket.destroy()
  front.stop()
  server.stop()
  const forwardedBytes = []
  for (const event of trace.events) if (event.forwarded) forwardedBytes.push(event.forwarded)
  return {
    events: trace.events,
    firstResponse: firstResponse,
    firstConnectionClosed: firstConnectionClosed,
    frontEndForwarded: summarise(trace.events, pair.frontEnd.label),
    backEndFramed: summarise(trace.events, pair.backEnd.label),
    leftovers: trace.events.filter(function (event) { return event.kind === 'leftover' }),
    forwardedBytes: forwardedBytes,
  }
}

// Sends a probe straight to the back end, as if something had bypassed the front end.
async function runBackEndOnly(pairName, probe) {
  const trace = { events: [], add: function (event) { trace.events.push(event) } }
  const server = await backEnd.startBackEnd(PAIRS[pairName].backEnd, trace)
  const client = openClient(server.port)
  const response = await sendAndRead(client, probe.bytes)
  await pause(50)
  const closed = client.closed
  client.socket.destroy()
  server.stop()
  return { response: response, closed: closed, events: trace.events }
}

function formatEvent(event) {
  if (event.kind === 'rejected') return event.who + ' | rejected with ' + event.code + ': ' + event.reason + ', connection closed'
  if (event.kind === 'leftover') return event.who + ' | ' + event.text.length + ' bytes left on the connection: ' + JSON.stringify(event.text)
  if (event.kind === 'unframed-at-close') return event.who + ' | connection closed holding ' + event.text.length + ' unframed bytes: ' + JSON.stringify(event.text)
  const line = event.who + ' | ' + event.requestLine + ' | framed by ' + event.note + ' | body ' + event.bodyLength + ' bytes'
  if (!event.forwarded) return line
  return line + '\n' + event.who + ' | forwarded ' + JSON.stringify(event.forwarded)
}

module.exports = { PAIRS, runProbe, runBackEndOnly, formatEvent, openClient, sendAndRead, pause }


==================== FILE 6 OF 9: run-trace.js ====================

'use strict'
// run-trace.js: prints how each side framed the same bytes.
// Usage: node run-trace.js mismatched space-before-colon
//        node run-trace.js corrected space-before-colon
//        node run-trace.js mismatched space-before-colon no-reuse

const harness = require('./harness')
const probes = require('./probes')

function showBytes(text) {
  return text.split('\r').join('\\r').split('\n').join('\\n\n')
}

async function main() {
  const pairName = process.argv[2]
  const probe = probes.findProbe(process.argv[3])
  const reuse = process.argv[4] !== 'no-reuse'
  const run = await harness.runProbe(pairName, probe, { reuseBackendConnection: reuse })
  console.log('probe: ' + probe.name + ' | pair: ' + pairName + ' | back-end connection reuse: ' + (reuse ? 'on' : 'off'))
  console.log('client sent:')
  console.log(showBytes(probe.bytes))
  console.log('then: GET /second')
  for (const event of run.events) console.log(harness.formatEvent(event))
  const agree = JSON.stringify(run.frontEndForwarded) === JSON.stringify(run.backEndFramed)
  console.log('front end forwarded: ' + run.frontEndForwarded.join(' / '))
  console.log('back end framed:     ' + run.backEndFramed.join(' / '))
  console.log('verdict: ' + (agree ? 'boundaries agree' : 'BOUNDARIES DISAGREE'))
}

main()


==================== FILE 7 OF 9: differential.test.js ====================

'use strict'
// differential.test.js: regression test for a front end and back end pair.
// PAIR=mismatched node --test --test-reporter=spec   (expected to fail)
// PAIR=corrected node --test --test-reporter=spec    (expected to pass)

const test = require('node:test')
const assert = require('node:assert')
const harness = require('./harness')
const probes = require('./probes')
const framing = require('./framing')

const PAIR = process.env.PAIR || 'corrected'
const REUSE = { reuseBackendConnection: true }

test(PAIR + ': both sides find the same message boundaries', async function () {
  for (const probe of probes.PROBES) {
    const run = await harness.runProbe(PAIR, probe, REUSE)
    assert.deepStrictEqual(run.backEndFramed, run.frontEndForwarded, probe.name)
    assert.strictEqual(run.leftovers.length, 0, probe.name + ' left bytes on a back-end connection')
  }
})

test(PAIR + ': ambiguous framing is refused at the front end and the connection closed', async function () {
  for (const probe of probes.PROBES) {
    if (!probe.ambiguous) continue
    const run = await harness.runProbe(PAIR, probe, REUSE)
    assert.ok(run.firstResponse && run.firstResponse.statusLine.includes(' 400 '), probe.name + ' was not refused with 400')
    assert.ok(run.firstConnectionClosed, probe.name + ' kept the client connection open')
    assert.strictEqual(run.frontEndForwarded.length, 1, probe.name + ' reached the back end')
  }
})

test(PAIR + ': the back end refuses ambiguous framing on its own', async function () {
  for (const probe of probes.PROBES) {
    if (!probe.ambiguous) continue
    const run = await harness.runBackEndOnly(PAIR, probe)
    assert.ok(run.response && run.response.statusLine.includes(' 400 '), probe.name + ' was not refused with 400')
    assert.ok(run.closed, probe.name + ' kept the connection open')
  }
})

test(PAIR + ': every forwarded message carries at most one framing header', async function () {
  for (const probe of probes.PROBES) {
    const run = await harness.runProbe(PAIR, probe, REUSE)
    for (const bytes of run.forwardedBytes) {
      const head = bytes.slice(0, bytes.indexOf('\r\n\r\n')).split('\r\n')
      let framingHeaders = 0
      for (const line of head) if (framing.isFramingHeader(line)) framingHeaders += 1
      assert.ok(framingHeaders <= 1, probe.name + ' forwarded ' + framingHeaders + ' framing headers')
    }
  }
})


==================== FILE 8 OF 9: serve-pair.js ====================

'use strict'
// serve-pair.js: starts a front end and a back end on loopback and leaves them
// running, printing each framing decision as it happens. Ctrl+C stops both.
// Usage: node serve-pair.js mismatched

const backEnd = require('./back-end')
const proxy = require('./proxy')
const harness = require('./harness')

async function main() {
  const pair = harness.PAIRS[process.argv[2]]
  const trace = { add: function (event) { console.log(harness.formatEvent(event)) } }
  const server = await backEnd.startBackEnd(pair.backEnd, trace)
  const front = await proxy.startProxy(pair.frontEnd, server.port, { reuseBackendConnection: true }, trace)
  console.log('front end listening on 127.0.0.1 port ' + front.port + ', back end on port ' + server.port)
  process.on('SIGINT', function () { front.stop(); server.stop() })
}

main()


==================== FILE 9 OF 9: send-probe.js ====================

'use strict'
// send-probe.js: sends one probe, then the follow-up request, to a front end
// running on this machine, and prints what came back. The address is fixed
// to 127.0.0.1: only the port can be chosen.
// Usage: node send-probe.js 8080 space-before-colon

const harness = require('./harness')
const probes = require('./probes')

function describe(response, client) {
  if (response) return response.statusLine
  return 'no complete response; raw bytes received: ' + JSON.stringify(client.buffer)
}

async function main() {
  const port = Number(process.argv[2])
  const probe = probes.findProbe(process.argv[3])
  const client = harness.openClient(port)
  const first = await harness.sendAndRead(client, probe.bytes)
  console.log('probe ' + probe.name + ': ' + describe(first, client))
  await harness.pause(50)
  if (client.closed) {
    console.log('the front end closed the connection after the probe')
    return
  }
  const second = await harness.sendAndRead(client, probes.FOLLOW_UP)
  console.log('follow-up GET /second: ' + describe(second, client))
  client.socket.destroy()
}

main()


==================== OUTPUT RECORDED FOR THIS PAGE ====================

Recorded with Node.js v26.0.0 on macOS. Port numbers and test durations change from run to run.

--- Run 1. Command: node run-trace.js mismatched space-before-colon

probe: space-before-colon | pair: mismatched | back-end connection reuse: on
client sent:
POST /submit HTTP/1.1\r\n
Host: lab.test\r\n
Content-Length: 13\r\n
Transfer-Encoding : chunked\r\n
\r\n
0\r\n
\r\n
LEFTOVER
then: GET /second
front end | POST /submit HTTP/1.1 | framed by Content-Length: 13 (last of 1) | body 13 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 13\r\nTransfer-Encoding : chunked\r\n\r\n0\r\n\r\nLEFTOVER"
back end  | POST /submit HTTP/1.1 | framed by Transfer-Encoding: chunked | body 0 bytes
back end  | 8 bytes left on the connection: "LEFTOVER"
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | LEFTOVERGET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end forwarded: POST /submit HTTP/1.1, body 13 bytes / GET /second HTTP/1.1, body 0 bytes
back end framed:     POST /submit HTTP/1.1, body 0 bytes / LEFTOVERGET /second HTTP/1.1, body 0 bytes
verdict: BOUNDARIES DISAGREE

--- Run 2. Command: node run-trace.js mismatched two-different-lengths

probe: two-different-lengths | pair: mismatched | back-end connection reuse: on
client sent:
POST /submit HTTP/1.1\r\n
Host: lab.test\r\n
Content-Length: 0\r\n
Content-Length: 8\r\n
\r\n
LEFTOVER
then: GET /second
front end | POST /submit HTTP/1.1 | framed by Content-Length: 8 (last of 2) | body 8 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 0\r\nContent-Length: 8\r\n\r\nLEFTOVER"
back end  | POST /submit HTTP/1.1 | framed by Content-Length: 0 (first of 2) | body 0 bytes
back end  | 8 bytes left on the connection: "LEFTOVER"
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | LEFTOVERGET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end forwarded: POST /submit HTTP/1.1, body 8 bytes / GET /second HTTP/1.1, body 0 bytes
back end framed:     POST /submit HTTP/1.1, body 0 bytes / LEFTOVERGET /second HTTP/1.1, body 0 bytes
verdict: BOUNDARIES DISAGREE

--- Run 3. Command: node run-trace.js mismatched space-before-colon no-reuse

probe: space-before-colon | pair: mismatched | back-end connection reuse: off
(the "client sent:" block is the same as in run 1 and is left out here)
then: GET /second
front end | POST /submit HTTP/1.1 | framed by Content-Length: 13 (last of 1) | body 13 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 13\r\nTransfer-Encoding : chunked\r\n\r\n0\r\n\r\nLEFTOVER"
back end  | POST /submit HTTP/1.1 | framed by Transfer-Encoding: chunked | body 0 bytes
back end  | 8 bytes left on the connection: "LEFTOVER"
back end  | connection closed holding 8 unframed bytes: "LEFTOVER"
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end forwarded: POST /submit HTTP/1.1, body 13 bytes / GET /second HTTP/1.1, body 0 bytes
back end framed:     POST /submit HTTP/1.1, body 0 bytes / GET /second HTTP/1.1, body 0 bytes
verdict: BOUNDARIES DISAGREE

--- Run 4. Command: node run-trace.js corrected space-before-colon

probe: space-before-colon | pair: corrected | back-end connection reuse: on
(the "client sent:" block is the same as in run 1 and is left out here)
then: GET /second
front end | rejected with 400: whitespace between field name and colon, connection closed
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end forwarded: GET /second HTTP/1.1, body 0 bytes
back end framed:     GET /second HTTP/1.1, body 0 bytes
verdict: boundaries agree

--- Run 5. Command: node run-trace.js corrected repeated-equal-lengths

probe: repeated-equal-lengths | pair: corrected | back-end connection reuse: on
client sent:
POST /submit HTTP/1.1\r\n
Host: lab.test\r\n
Content-Length: 8\r\n
Content-Length: 8\r\n
\r\n
lab-body
then: GET /second
front end | POST /submit HTTP/1.1 | framed by Content-Length: 8 (2 equal values collapsed) | body 8 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 8\r\n\r\nlab-body"
back end  | POST /submit HTTP/1.1 | framed by Content-Length: 8 | body 8 bytes
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end forwarded: POST /submit HTTP/1.1, body 8 bytes / GET /second HTTP/1.1, body 0 bytes
back end framed:     POST /submit HTTP/1.1, body 8 bytes / GET /second HTTP/1.1, body 0 bytes
verdict: boundaries agree

--- Run 6. Command: node run-trace.js corrected plain-chunked

probe: plain-chunked | pair: corrected | back-end connection reuse: on
client sent:
POST /submit HTTP/1.1\r\n
Host: lab.test\r\n
Transfer-Encoding: chunked\r\n
\r\n
8\r\n
lab-body\r\n
0\r\n
\r\n

then: GET /second
front end | POST /submit HTTP/1.1 | framed by Transfer-Encoding: chunked | body 8 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 8\r\n\r\nlab-body"
back end  | POST /submit HTTP/1.1 | framed by Content-Length: 8 | body 8 bytes
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end forwarded: POST /submit HTTP/1.1, body 8 bytes / GET /second HTTP/1.1, body 0 bytes
back end framed:     POST /submit HTTP/1.1, body 8 bytes / GET /second HTTP/1.1, body 0 bytes
verdict: boundaries agree

--- Run 7. Command: PAIR=mismatched node --test --test-reporter=spec differential.test.js
(excerpt: stack traces, file paths and object dumps are left out)

✖ mismatched: both sides find the same message boundaries (115.755791ms)
✖ mismatched: ambiguous framing is refused at the front end and the connection closed (106.381167ms)
✖ mismatched: the back end refuses ambiguous framing on its own (53.336417ms)
✖ mismatched: every forwarded message carries at most one framing header (105.947167ms)
ℹ tests 4
ℹ suites 0
ℹ pass 0
ℹ fail 4
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 463.697583

✖ failing tests:

test at differential.test.js:15:1
✖ mismatched: both sides find the same message boundaries (115.755791ms)
  AssertionError [ERR_ASSERTION]: space-before-colon
  + actual - expected
    [
  +   'POST /submit HTTP/1.1, body 0 bytes',
  +   'LEFTOVERGET /second HTTP/1.1, body 0 bytes'
  -   'POST /submit HTTP/1.1, body 13 bytes',
  -   'GET /second HTTP/1.1, body 0 bytes'
    ]

test at differential.test.js:23:1
✖ mismatched: ambiguous framing is refused at the front end and the connection closed (106.381167ms)
  AssertionError [ERR_ASSERTION]: space-before-colon was not refused with 400

test at differential.test.js:33:1
✖ mismatched: the back end refuses ambiguous framing on its own (53.336417ms)
  AssertionError [ERR_ASSERTION]: space-before-colon was not refused with 400

test at differential.test.js:42:1
✖ mismatched: every forwarded message carries at most one framing header (105.947167ms)
  AssertionError [ERR_ASSERTION]: space-before-colon forwarded 2 framing headers

--- Run 8. Command: PAIR=corrected node --test --test-reporter=spec differential.test.js

✔ corrected: both sides find the same message boundaries (533.750875ms)
✔ corrected: ambiguous framing is refused at the front end and the connection closed (321.097875ms)
✔ corrected: the back end refuses ambiguous framing on its own (160.049208ms)
✔ corrected: every forwarded message carries at most one framing header (534.534125ms)
ℹ tests 4
ℹ suites 0
ℹ pass 4
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 1639.017541

--- Run 9. Command: node serve-pair.js mismatched, then from a second terminal:
node send-probe.js 52831 space-before-colon
node send-probe.js 52831 two-different-lengths

send-probe.js printed:
probe space-before-colon: HTTP/1.1 200 OK
follow-up GET /second: HTTP/1.1 200 OK
probe two-different-lengths: HTTP/1.1 200 OK
follow-up GET /second: HTTP/1.1 200 OK

serve-pair.js printed:

front end listening on 127.0.0.1 port 52831, back end on port 52819
front end | POST /submit HTTP/1.1 | framed by Content-Length: 13 (last of 1) | body 13 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 13\r\nTransfer-Encoding : chunked\r\n\r\n0\r\n\r\nLEFTOVER"
back end  | POST /submit HTTP/1.1 | framed by Transfer-Encoding: chunked | body 0 bytes
back end  | 8 bytes left on the connection: "LEFTOVER"
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | LEFTOVERGET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | POST /submit HTTP/1.1 | framed by Content-Length: 8 (last of 2) | body 8 bytes
front end | forwarded "POST /submit HTTP/1.1\r\nHost: lab.test\r\nContent-Length: 0\r\nContent-Length: 8\r\n\r\nLEFTOVER"
back end  | POST /submit HTTP/1.1 | framed by Content-Length: 0 (first of 2) | body 0 bytes
back end  | 8 bytes left on the connection: "LEFTOVER"
front end | GET /second HTTP/1.1 | framed by no framing header | body 0 bytes
front end | forwarded "GET /second HTTP/1.1\r\nHost: lab.test\r\n\r\n"
back end  | LEFTOVERGET /second HTTP/1.1 | framed by no framing header | body 0 bytes

--- Run 10. Command: node serve-pair.js corrected, then from a second terminal:
node send-probe.js 54043 space-before-colon
node send-probe.js 54043 two-different-lengths

send-probe.js printed:
probe space-before-colon: HTTP/1.1 400 Bad Request
the front end closed the connection after the probe
probe two-different-lengths: HTTP/1.1 400 Bad Request
the front end closed the connection after the probe

serve-pair.js printed:

front end listening on 127.0.0.1 port 54043, back end on port 54042
front end | rejected with 400: whitespace between field name and colon, connection closed
front end | rejected with 400: Content-Length values disagree, connection closed


WHAT THE OUTPUT SHOWS

- Runs 1 and 2: the front end forwards a 13-byte or 8-byte body, and the back end frames a body of 0 bytes. The 8 bytes LEFTOVER stay on the back-end connection, and the back end reads the next request as LEFTOVERGET /second.
- Run 9: the client's response to the follow-up is an ordinary 200 OK. Only the back end's own record shows that it read LEFTOVERGET. Find a disagreement by comparing the two components' logs, not by reading responses.
- Run 3: with a new back-end connection for every request, the 8 bytes are discarded when that connection closes, and the follow-up arrives intact. The two sides still disagree about the first request's body. Turning off connection reuse limits where leftover bytes can go. It does not make the parsers agree.
- Runs 4 to 6 and 10: the corrected front end refuses each ambiguous probe with 400 and closes the client connection, collapses two equal Content-Length values into one, and forwards a chunked body as a decoded body with one Content-Length.
- Runs 7 and 8: the regression test fails all four checks on the mismatched pair and passes all four on the corrected pair.


VERIFICATION CHECKLIST FOR A FRONT END AND BACK END YOU OWN

How to use it: run your own front end and back end on one machine, at the versions and with the settings you run in production, listening on 127.0.0.1. Send each probe with send-probe.js, then compare the two components' access logs for the same minute. Tick an item only when you have seen the behaviour, and write down the version and setting that produced it. RFC 9112 is HTTP/1.1, RFC 9110 is HTTP Semantics and RFC 9113 is HTTP/2.

Normalisation at the front end
[ ] A request with both Content-Length and Transfer-Encoding is refused with 400 and the connection closed, or forwarded with the Content-Length removed and the body framed by Transfer-Encoding alone. It is not forwarded with both. RFC 9112 section 6.1: a server MAY reject such a request or process it using Transfer-Encoding alone, and MUST close the connection after responding. Section 6.3: an intermediary that chooses to forward it MUST first remove the received Content-Length. Probe: length-and-chunked.
[ ] Whitespace between a header field name and its colon gets 400. RFC 9112 section 5.1 (MUST). Probe: space-before-colon.
[ ] A Transfer-Encoding in which chunked is not the final coding gets 400 and the connection closed. RFC 9112 section 6.3 (MUST). A transfer coding the server does not understand gets 501. RFC 9112 section 6.1 (SHOULD).
[ ] A header line that begins with a space or tab (obsolete line folding) is refused with 400, or each fold is replaced with spaces before the value is read or forwarded. RFC 9112 section 5.2 (MUST do one or the other).
[ ] A bare CR in the header section is treated as invalid, or replaced with a space before the message is processed or forwarded. RFC 9112 section 2.2 (MUST do one or the other).
[ ] A lone LF used as a line ending is handled the same way by both components. RFC 9112 section 2.2 says a recipient MAY recognise it, so two compliant parsers can differ here.
[ ] Every forwarded message carries at most one framing header, and its Content-Length matches the body forwarded. RFC 9110 section 8.6: a sender MUST NOT forward a message with a Content-Length value known to be incorrect. Probes: plain-chunked and repeated-equal-lengths.
[ ] If the front end speaks HTTP/2 to clients and HTTP/1.1 to the back end, it treats as malformed, and does not forward, an HTTP/2 request that contains Transfer-Encoding, a content-length that differs from the total of its DATA frames, or a field value containing CR, LF or NUL. RFC 9113 sections 8.1.1, 8.2.1 and 8.2.2 (MUST). The probes in this lab are HTTP/1.1 only, so this item needs an HTTP/2 client that can send such requests to your local copy.

Duplicate header handling
[ ] Two Content-Length values that differ get 400 and the connection closed. RFC 9112 section 6.3 (MUST). Probe: two-different-lengths.
[ ] Repeated equal Content-Length values are either refused or collapsed to one value before forwarding, and you know which. RFC 9110 section 8.6 (MAY do either). The back end refuses any repetition that reaches it. Probe: repeated-equal-lengths.
[ ] Two Transfer-Encoding lines are read as one list, and chunked listed twice is refused. RFC 9110 section 5.3 lets a recipient combine field lines with the same name. RFC 9112 section 6.1 says a sender MUST NOT apply chunked more than once.
[ ] A look-alike name such as Transfer_Encoding is not mapped onto Transfer-Encoding anywhere in the chain, including in variables passed to application code. RFC 9110 section 17.10.
[ ] A header line, or a header section, larger than a component will process gets a 4xx response rather than being ignored. RFC 9110 section 5.4 (MUST).

Connection reuse
[ ] After the front end refuses a request, it closes that client connection. Probes: space-before-colon, two-different-lengths and length-and-chunked.
[ ] After the back end refuses a request, it closes the connection, and the front end sends the next request on a fresh connection.
[ ] With back-end connection reuse on, send each probe, then the follow-up from a second connection. The back end logs the follow-up's request line exactly as sent: GET /second, not LEFTOVERGET /second.
[ ] If your front end documents an option to stop reusing back-end connections, run the probes with it on and with it off, and record the difference. Run 3 shows what that option changes and what it leaves alone.

Logging
[ ] Both components log, for each request, the time, the request line, the framing header used and the body length they framed. Compare the two logs for the probe window. A request line in the back-end log that is missing from the front-end log is the sign of a disagreement.
[ ] Refused requests (400 and 501) appear in the logs with a reason, so a burst of refusals after a configuration change is visible.

Before anything touches production
[ ] Any check on production is in a written scope and rules of engagement, signed by the owner of each target.
[ ] Each host's testing policy has been read for that target, including any CDN or load balancer run by another business.
[ ] Shared production front ends are not used for learning or for repeating these probes.

What HTTP request smuggling is

HTTP request smuggling is what happens when two components that handle the same HTTP traffic, such as a reverse proxy, CDN or load balancer and the back-end server behind it, disagree about where one request ends and the next begins.

RFC 9112, the current HTTP/1.1 specification, describes it as a technique that exploits differences in protocol parsing among various recipients to hide additional requests, which might otherwise be blocked or disabled by policy, within an apparently harmless request. For the technique it cites a June 2005 paper, HTTP Request Smuggling, by Chaim Linhart, Amit Klein, Ronen Heled and Steve Orrin, and the OWASP Web Security Testing Guide names the same four researchers as first discovering it in 2005.

MITRE's Common Weakness Enumeration records the underlying weakness as CWE-444, Inconsistent Interpretation of HTTP Requests, with HTTP Request Smuggling and HTTP Smuggling among its alternate terms. Its description centres on the component in the middle: an intermediary HTTP agent, such as a proxy or firewall, that does not interpret malformed requests or responses consistently with how the entities at the ultimate destination will process them.

CWE adds that the weakness is usually the result of outdated or incompatible HTTP protocol versions in the agents involved.

The OWASP Web Security Testing Guide v4.2 covers it under WSTG-INPV-15, Testing for HTTP Splitting Smuggling, whose objectives include assessing whether the chain of communication is vulnerable to smuggling. The guide places smuggling in its grey-box testing section, because it needs some knowledge of the agents handling the messages, such as the web server, proxy and firewall, and it notes that HTTP smuggling does not exploit any vulnerability in the target web application.

HTTP desync attack is the name in the title of James Kettle's 2019 PortSwigger research, HTTP Desync Attacks: Request Smuggling Reborn, which says request smuggling was first documented in 2005 by Watchfire.

Why the front end and back end must agree on where a request ends

HTTP/1.1 puts nothing between two requests that share a connection.

In Kettle's words, requests are simply placed back to back, and the server parses headers to work out where each one ends and the next one starts. By itself, he writes, this is harmless. PortSwigger's Web Security Academy describes the setting where it stops being harmless: a front-end server typically sends several requests over the same back-end network connection, so it is crucial that the front-end and back-end systems agree about the boundaries between requests.

Two header fields decide the boundary. RFC 9112 section 6 says the presence of a body in a request is signalled by Content-Length or Transfer-Encoding, and that request framing is independent of the method. Section 6.3 adds that requests are explicitly framed by length or transfer coding, and that a request with neither ends immediately after its header section.

Every parser in a chain has to answer the same question from the same two fields, so any rule two parsers apply differently is a place where they can disagree.

When they do disagree, bytes that one side counts as the body of the current request are, to the other side, the start of the next one. The Academy describes the effect: part of one request is interpreted by the back end as the start of the next request and is effectively prepended to it.

Kettle's paper describes that prefix landing at the start of the next legitimate user's request, and makes the point about parser quirks directly: each one is harmless if both the front end and the back end have it, and a major threat otherwise.

That is the HTTP parser inconsistency behind every variant on this page. Neither component has to be wrong on its own terms, only different from its neighbour.

CWE-444 lists what can follow. A cache in front of the application can be tricked into storing one page's content under another page's URL, which is web cache poisoning and has its own guide in this library. A request can be structured to get past a firewall's protection and gain unauthorised access to a web application.

A request can invoke a script or page that returns client credentials. RFC 9112 describes the hidden request as one that might otherwise be blocked or disabled by policy, which is the concern for any control enforced only at the front end, such as a block rule or a rate limit: it acts on the requests the front end framed, not on the ones the back end ends up processing.

What HTTP/1.1 requires when framing is ambiguous

RFC 9112 (HTTP/1.1, STD 99) and RFC 9110 (HTTP Semantics, STD 97), both published in June 2022, set the rules.

Section 11.2 of RFC 9112 says it introduced new requirements on request parsing, particularly on message framing in section 6.3, to reduce the effectiveness of request smuggling. The rules below keep each requirement's own wording: MUST, SHOULD or MAY.

Where a rule says MAY, two compliant components can still choose differently, which is why the lab's checklist asks you to confirm that your front end and back end make the same choice.

Content-Length and Transfer-Encoding in the same request

This is the combination behind the classic desync patterns, and the standard is explicit about it. 1 min read

Malformed and repeated Content-Length

Two Content-Length values that differ appear in both the OWASP testing guide and CWE-444's first example. 1 min read

Whitespace, line endings and look-alike names

Small formatting differences are where an obfuscated header slips past one parser and not the other. 1 min read

CL.TE, TE.CL and TE.TE: the classic desync patterns

PortSwigger's Web Security Academy names each case by the header each side uses, front end first.

The Academy explains why the cases arise: some servers do not support Transfer-Encoding in requests, and some that do can be induced not to process it if the header is obfuscated in some way.

  • CL.TE:the front end uses Content-Length and the back end uses Transfer-Encoding. The back end stops at the zero-length chunk and treats the bytes after it as the start of the next request.
  • TE.CL:the front end uses Transfer-Encoding and the back end uses Content-Length, so the back end stops earlier than the front end did and the rest of the chunked body becomes the next request.
  • TE.TE:both support Transfer-Encoding, but one of them can be induced not to process it by obfuscating the header. What follows plays out as CL.TE or TE.CL, depending on which side ignored it.

Obfuscated headers and duplicate lengths

Kettle's 2019 paper lists variants of the Transfer-Encoding header that only some servers recognise, and says each was used to exploit at least one system during his research. One of them is a space between the field name and the colon, the form RFC 9112 section 5.1 requires a server to reject with 400.

Two Content-Length headers with different values is a separate variant. CWE-444's first example has a proxy that ignores the first of two Content-Length headers and a web server that uses it. Kettle wrote in 2019 that the dual Content-Length technique rarely works because many systems sensibly reject requests with multiple content-length headers, and RFC 9112 section 6.3 requires a server to refuse differing values with 400.

Later research widened the list. Kettle's 2025 paper, HTTP/1.1 must die: the desync endgame, works with four length interpretations: Content-Length, Transfer-Encoding, an implicit zero, and HTTP/2's built-in length. The lab on this page traces two of the classic forms: a Transfer-Encoding header with a space before the colon, which produces a CL.TE desync, and two different Content-Length values.

How HTTP/2 downgrading changes the picture

HTTP/2 frames messages differently.

RFC 9113 says HTTP/2 uses DATA frames to carry message content and that chunked transfer encoding cannot be used. A content-length header is allowed, but a request whose content-length does not equal the total of its DATA frame payloads is malformed, and an intermediary that processes HTTP requests, that is, any intermediary not acting as a tunnel, MUST NOT forward a malformed request (section 8.1.1).

Transfer-Encoding is a connection-specific header field, and any HTTP/2 message containing one MUST be treated as malformed (section 8.2.2).

The risk comes back when HTTP/2 is translated into HTTP/1.1. Kettle's 2021 research, HTTP/2: The Sequel is Always Worse, calls this HTTP/2 downgrading: a front end speaks HTTP/2 with clients but rewrites requests into HTTP/1.1 before forwarding them to the back end.

He writes that front ends speaking HTTP/2 almost always use HTTP/2's built-in message length, while the back end receiving the downgraded request has to use Content-Length or Transfer-Encoding. That leads to two further cases he names H2.CL and H2.TE.

HTTP/2's binary format also lets a header value carry characters that end a line in HTTP/1.1. RFC 9113 section 8.2.1 says a field value MUST NOT contain NUL, LF or CR, that a message which breaks this MUST be treated as malformed, and that failure to validate fields can be exploited for request smuggling when messages are forwarded using HTTP/1.1.

OWASP ASVS 5.0 turns these into Level 3 requirements 4.2.3 and 4.2.4: do not send or accept HTTP/2 or HTTP/3 messages with connection-specific header fields such as Transfer-Encoding, and only accept HTTP/2 and HTTP/3 requests whose header fields and values contain no CR, LF or CRLF sequences.

The research is direct about the remedy. Kettle's 2021 paper advises avoiding HTTP/2 downgrading and using HTTP/2 end to end. His 2025 paper says upstream HTTP/2 makes desync vulnerabilities vastly less likely, while implementation bugs can still be expected, and that downgrading provides minimal security benefit and actually makes websites more exposed to desync attacks.

He adds that disabling HTTP/1 between the browser and the front end is not required, because those connections are rarely shared between different users; the connections to convert are the upstream ones.

What the parser trace lab shows

The lab is an illustration written for this page.

It is two small programs built with Node.js built-in modules only: a front end that frames each request with its own parser and forwards it, and a back end that reads requests one after another from the connection the front end opens.

Both listen on 127.0.0.1, on ports the operating system picks, and the harness that drives them connects nowhere else. Each component prints how it framed the bytes, so the disagreement is visible rather than inferred.

In the mismatched pair, each parser takes a different shortcut. The front end recognises a Transfer-Encoding header only when its name matches exactly, and uses the last Content-Length when there are several. The back end trims spaces from header names, accepts any Transfer-Encoding value that contains chunked, and uses the first Content-Length.

Sent a request carrying "Transfer-Encoding : chunked", with a space before the colon, and "Content-Length: 13", the front end forwards a 13-byte body. The back end decodes a chunked body that ends after five bytes, leaves the 8 bytes LEFTOVER on the connection, and reads the next request as LEFTOVERGET /second.

The probe text is inert by design: LEFTOVER is not a method or a request line, so its only effect is a visibly broken method on the next message.

Two details in the recorded output are worth noticing. First, the client's response to the follow-up request was an ordinary 200 OK; only the back end's own record shows it read LEFTOVERGET. A disagreement is found by comparing what each component logged, not by reading responses.

Second, when the front end opens a new back-end connection for every request, the 8 bytes are discarded as that connection closes and the follow-up arrives intact, but the two sides still disagree about the first request's body. Turning off connection reuse limits where leftover bytes can go. It does not make the parsers agree.

In the corrected pair, both components refuse the ambiguous forms with 400 and close the connection, following the RFC 9112 rules above, and the front end forwards each request it accepts with one Content-Length that matches the body it decoded.

The regression test sends every probe through a pair and checks four things: both sides find the same boundaries, the front end refuses ambiguous framing and closes the connection, the back end refuses it on its own, and no forwarded message carries more than one framing header. It failed all four checks on the mismatched pair and passed all four on the corrected pair.

The lab is for learning, and for checking a front end and back end you own, run locally at the versions and settings you use in production. Do not point the probes, or any ambiguous request, at a system you do not own or at shared production infrastructure.

Where a front end shares back-end connections between visitors, leftover bytes land on whoever's request comes next, so an ambiguous request can affect other people's traffic.

Request smuggling testing without touching other people's traffic

Request smuggling is unusual in how a test can go wrong.

Kettle's 2019 paper notes that on a live site, if another user's request reaches the poisoned connection before the tester's own follow-up, that user gets the corrupted response. It also says that even flawed request smuggling attacks can have side effects, which makes live websites a poor choice of training ground.

A differential test on components you own avoids both problems: send the same ambiguous bytes through your own front end and back end, and compare how each one framed them.

  • Reproduce the parts of the chain you run yourself: the same proxy and server software, at the same versions and with the same settings, listening on 127.0.0.1. A managed CDN or cloud load balancer cannot be copied this way, so read its documentation for the parsing and normalisation options it offers instead.
  • Send each probe once, then an ordinary follow-up request, and compare what each component logged: the request line, the framing header it used and the body length. Matching responses prove little. Matching logs are the evidence.
  • Repeat with back-end connection reuse on and off, if your front end has that option, and with each strictness or normalisation setting switched both ways, so you know which setting is doing the work.
  • Keep the probes inert. The lab's probes carry the word LEFTOVER rather than a request, so a disagreement shows up as a broken method name and nothing else.
  • Turn each rule you confirm into a regression test like the lab's, and rerun it whenever a component in the chain is upgraded or reconfigured.

Production is a different decision

Sending ambiguous requests through shared production infrastructure is the kind of activity that a written rules of engagement document and each host's testing policy govern, because the connections involved carry other people's requests. A CDN or firewall in front of a site may also block test traffic and may have terms of its own.

Settle those questions in writing before any request is sent, and keep learning and repeat runs on a local copy.

Request smuggling prevention: what closes the gap

The fixes below run from the one that removes the most ambiguity to the ones that limit what a remaining disagreement can reach.

ASVS 5.0 requirement 4.2.1, at Level 2, states the goal they share: all application components, including load balancers, firewalls and application servers, determine the boundaries of incoming HTTP messages using the appropriate mechanism for the HTTP version.

Use HTTP/2 to the back end, and avoid downgrading

The Academy's first recommendation is to use HTTP/2 end to end and disable HTTP downgrading if possible. 1 min read

Normalise at the front end, refuse at the back end

Kettle's 2019 paper says specific instances can be resolved by reconfiguring the front end to normalise ambiguous requests before routing them onward, and that normalising is not an option for back-end servers, which need to outright reject ambiguous requests and drop the associated connection. 1 min read

Refuse ambiguous messages and close the connection

Every MUST in the RFC 9112 rules above that ends in "400 and close the connection" is a rule both components can apply. 1 min read

Stop reusing back-end connections where your product documents the option

Kettle's 2019 paper lists disabling back-end connection reuse entirely as one way to resolve the problem, alongside HTTP/2 to the back end, and his 2025 paper keeps it on the list for sites that must stay on upstream HTTP/1.1, noting that it may impact performance. 1 min read

Use your product's strictness settings, and leave them on

Several products document settings for exactly this. 1 min read

Keep every component patched, and retest after upgrades

CWE-444's observed examples are flaws in specific products: an SSL/TLS-capable proxy, a caching proxy server, a server platform, web servers and HTTP servers. 1 min read

Log what each side framed

The evidence of a disagreement is a request the back end processed that the front end did not log, so both sides need to record the request line, the framing they used and the body length. 1 min read

Where request smuggling fits in a Clever Ops test

A Clever Ops web application and API penetration test is a signed-in test of a custom application and the API behind it.

A CDN, load balancer or proxy in front of that application may be run by another business, and a CDN or firewall in front of a site may block test traffic or have terms of its own. If you want request framing between your front end and your application considered, raise it on the scoping call, so it is either in the written scope or listed as an exclusion, and the report records what was out of scope or not performed.

Any check on production runs under the same conduct rules as the rest of the test. Testing starts only after the owner of each target has signed an authorisation, and runs to written rules of engagement. Your hosting provider's testing policy is checked for each target before testing begins, in case it asks for notice or approval.

Destructive actions are off by default for real people's accounts and records that existed before the test, and reset, lockout and deletion checks run only on test accounts and test records where the rules of engagement allow them.

A staging copy that matches production is preferred where one exists. If Clever Ops built or hosts the system, the work is a security review rather than an independent test, and the report says who built it and who hosts it.

Frequently asked questions

It is another name for HTTP request smuggling, used in the title of James Kettle's 2019 PortSwigger research, HTTP Desync Attacks: Request Smuggling Reborn. A front end and the back-end server behind it disagree about where one request ends, so bytes that one side treats as part of a request are read by the other as the start of the next request on the same connection.

No. Kettle's 2019 paper answers the question directly: HTTPS does not prevent it. TLS protects the connection between two parties, but it does not change how a front end and a back end each decide where a request ends once the bytes reach them.

The classic attack needs at least two parsers in a chain. Kettle's 2019 paper says a website free of load balancers, CDNs and reverse proxies is not threatened by the technique it describes, and that the more layers you introduce, the more likely you are to be vulnerable. PortSwigger's Web Security Academy also describes later browser-powered techniques that can expose single-server sites to request smuggling-style attacks, so the back-end items in the lab's checklist are still worth working through.

Used end to end, it removes most of the ambiguity: RFC 9113 frames bodies with DATA frames and treats any HTTP/2 message containing Transfer-Encoding as malformed. Kettle's 2025 paper says upstream HTTP/2 makes desync vulnerabilities vastly less likely, while warning that implementation bugs can still be expected. HTTP/2 on the client side only, downgraded to HTTP/1.1 for the back end, is different: he says downgrading provides minimal security benefit and actually makes websites more exposed to desync attacks.

RFC 9112 treats them as separate techniques. Response splitting, also called CRLF injection, relies on an application that decodes a request parameter and echoes it into a response header, so encoded line breaks make one response look like two. Request smuggling relies on two recipients parsing the same request differently. OWASP covers both in one test, WSTG-INPV-15, Testing for HTTP Splitting Smuggling.

Start with a local copy of the components you own, and do not send ambiguous requests to a system you do not own. On a live front end, connections to the back end can be shared between visitors, so an ambiguous request can affect someone else's request. If a check on production is wanted, it belongs in a written scope and rules of engagement, after each host's testing policy has been read.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.