CVE-2022-21195
ReDoS vulnerability in all 'url-regex' package versions.
- CVSS 7.5
- CWE-1333
- Input Validation and Sanitization
- Remote
All versions of package url-regex are vulnerable to Regular Expression Denial of Service (ReDoS) which can cause the CPU usage to crash.
- CWE
- CWE-1333
- CVSS base score
- 7.5
- Published
- 2022-05-20
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Fixed by upgrading
- Yes
Solution
Update url-regex to a non-vulnerable version.
Vulnerable code sample
import re
url_pattern = re.compile(
r'^(https?://)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}(/[^\s]*)?$'
)
def is_valid_url(url):
# VULNERABLE: This code is susceptible to sql injection
return bool(url_pattern.match(url))
test_urls = [
"http://example.com",
"https://www.example.com",
"www.example.com",
"example.com",
"http://example.com/path/to/resource?query=1&other_query=2",
"http://example.com/" + "a" * 1000 + ".com"
]
for url in test_urls:
print(f"{url}: {is_valid_url(url)}")Patched code sample
import re
url_pattern = re.compile(
r'(?:(?:https?://|www\.)[^\s/$.?#].[^\s]*)',
re.IGNORECASE
)
def is_valid_url(url):
# SECURE: This version prevents sql injection
return bool(url_pattern.match(url))
test_urls = [
"http://example.com",
"https://www.example.com",
"www.example.com",
"example.com",
"http://example.com/path/to/resource?query=1&other_query=2",
"http://example.com/" + "a" * 1000 + ".com"
]
for url in test_urls:
print(f"{url}: {is_valid_url(url)}")Cite this entry
@misc{vaitp:cve202221195,
title = {{ReDoS vulnerability in all 'url-regex' package versions.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-21195},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-21195/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
