CVE-2022-0391

7.5 HIGH

📋 TL;DR

This vulnerability in Python's urllib.parse module allows injection attacks via crafted URLs containing carriage return (\r) or line feed (\n) characters in the path component. Attackers can exploit this to manipulate URL parsing outcomes, potentially leading to various injection scenarios. This affects Python applications using urllib.parse for URL handling in vulnerable versions.

💻 Affected Systems

Products:
  • Python
  • Applications using Python's urllib.parse module
Versions: Python <3.10.0b1, <3.9.5, <3.8.11, <3.7.11, <3.6.14
Operating Systems: All operating systems running vulnerable Python versions
Default Config Vulnerable: ⚠️ Yes
Notes: Any application using urllib.parse.urlparse() or related functions with user-controlled input is vulnerable. This includes web frameworks, APIs, and command-line tools.

📦 What is this software?

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

Python by Python

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and scientific computing.

Learn more about Python →

⚠️ Risk & Real-World Impact

🔴

Worst Case

CRLF injection leading to HTTP response splitting, cache poisoning, or injection of malicious headers that could enable cross-site scripting (XSS), session hijacking, or server-side request forgery (SSRF).

🟠

Likely Case

CRLF injection enabling HTTP response splitting or header injection in web applications that process user-supplied URLs, potentially leading to cache poisoning or limited XSS.

🟢

If Mitigated

Limited impact if input validation and output encoding are properly implemented, though the vulnerability still exists at the parsing layer.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Proof-of-concept code is available in the Python bug tracker. Exploitation requires user-controlled input being passed to vulnerable functions.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Python 3.10.0b1, 3.9.5, 3.8.11, 3.7.11, 3.6.14 or later

Vendor Advisory: https://bugs.python.org/issue43882

Restart Required: Yes

Instructions:

1. Identify Python version with 'python --version'. 2. Update Python using package manager: 'apt update && apt upgrade python3' (Debian/Ubuntu) or 'yum update python3' (RHEL/CentOS). 3. Restart affected applications/services. 4. For compiled applications, recompile with patched Python.

🔧 Temporary Workarounds

Input validation for URLs

all

Sanitize user-supplied URLs before passing to urllib.parse by removing or rejecting CR/LF characters

import re
sanitized_url = re.sub(r'[\r\n]', '', user_input_url)

Use alternative parsing

all

Replace urllib.parse.urlparse() with custom validation or alternative libraries that handle CR/LF properly

🧯 If You Can't Patch

  • Implement strict input validation to reject URLs containing CR (\r) or LF (\n) characters
  • Use web application firewalls (WAF) with CRLF injection rules to block malicious requests

🔍 How to Verify

Check if Vulnerable:

Test with: python3 -c "from urllib.parse import urlparse; print(urlparse('http://example.com/path%0d%0aInjection:test'))" and check if CR/LF characters appear in parsed components

Check Version:

python --version  or  python3 --version

Verify Fix Applied:

After patching, same test should show CR/LF characters removed or properly handled in parsed output

📡 Detection & Monitoring

Log Indicators:

  • URLs containing %0d, %0a, \r, or \n in path components
  • Unusual HTTP headers or response splitting in web server logs

Network Indicators:

  • HTTP requests with encoded CR/LF characters in URLs
  • Abnormal HTTP responses with injected headers

SIEM Query:

source="web_logs" AND (url="*%0d*" OR url="*%0a*" OR url="*\\r*" OR url="*\\n*")

🔗 References

📤 Share & Export