Skip to content
Smuggling / CRLF Write-up Advanced

Abusing Client-Side Desync on Werkzeug

Werkzeug versions 2.1.0 to 2.1.1 mishandle POST request bodies on keep-alive connections, allowing an attacker to smuggle a partial request that desynchronises the browser's view of the connection. Chained with an open redirect, this lets an attacker poison the browser cache so a script file is loaded from an attacker-controlled server, leading to XSS and potential account takeover.

kevin_mizu Follow

Published on mizu.re

PDF Version can be found here

Mizu (@kevin_mizu), on mizu.re

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker could achieve XSS and potentially full account takeover, and because the redirect is a 308 permanent redirect, the malicious script location is cached in the victim's browser so the XSS triggers on subsequent page loads.

What the attacker needed

Victim visits attacker page; victim uses vulnerable Werkzeug 2.1.0-2.1.1; browser keeps connection alive; open redirect present

The fix

The text does not state a fix for the desync itself, but the open redirect was fixed by requiring both a scheme and a netloc before using the parsed host; the desync should be fixed by properly consuming or discarding unread request bodies on keep-alive connections.

How it was found

  1. Set up a Flask application running on a vulnerable Werkzeug version (2.1.0 or 2.1.1).
  2. Send a POST request whose body contains the beginning of another HTTP request.
  3. Observe that the server leaves the POST body in the connection queue and uses it as the start of the next request.
  4. Use a cross-site HTML form with text/plain encoding to send the smuggled request bytes from the victim's browser.
  5. Chain the desync with an open redirect to change the location of a script file to an attacker-controlled server.
  6. The browser caches the redirect and loads the malicious script, executing XSS.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When a web server keeps a connection open for several requests, it must carefully track where one request ends and the next begins. In the affected Werkzeug versions, leftover data from a POST request was treated as the start of the next request, so an attacker could sneak in the beginning of a request of their own. By combining this with a redirect flaw, the attacker could make the victim's browser load a malicious script from the attacker's server instead of the real site.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

More by kevin_mizu

View all

4 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.