Skip to content
Smuggling / CRLF Write-up Intermediate

Python urllib CRLF injection vulnerability

Python's urllib and urllib2 did not properly sanitise CRLF characters in URL parameters, allowing an attacker who controls a URL to inject arbitrary HTTP headers or Redis commands. This could lead to request splitting or command injection depending on the context.

coocoor.com

Published on coocoor.com

An issue was discovered in urllib2 in Python 2.x through 2.7.16 and urllib in Python 3.x through 3.7.3. CRLF injection is possible if the attacker controls a url parameter, as demonstrated by the first argument to urllib.request.urlopen with \r\n (specifically in the query string after a ? character) followed by an…

The author, on coocoor.com

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

Root cause

Likely, the URL parsing and request construction in urllib did not reject or encode carriage return and line feed characters in the query string, allowing them to be interpreted as header separators.

Impact

An attacker could inject arbitrary HTTP headers or Redis commands, potentially leading to request splitting or command execution, though the text does not specify the full extent.

What the attacker needed

Attacker controls a URL parameter

The fix

The vulnerability was fixed in multiple Python versions by properly handling CRLF characters in URLs.

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 program fetches a web address, it sends a request to a server. If the address contains special newline characters, the program might treat them as the end of one request and the start of another, letting an attacker sneak in extra instructions. This is called CRLF injection because the characters are carriage return and line feed.

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.

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.