CVE-2012-2921
Python-feedparser < 5.1.2 Denial of service with crafted non-ASCII XML ENTITY in documents
- CVSS 5.0
- CWE-399
- Resource Management
- Remote
Universal Feed Parser (aka feedparser or python-feedparser) before 5.1.2 allows remote attackers to cause a denial of service (memory consumption) via a crafted XML ENTITY declaration in a non-ASCII encoded document.
- CWE
- CWE-399
- CVSS base score
- 5.0
- Published
- 2012-05-21
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Resource Management
- Subcategory
- Memory Leaks
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- feedparser
- Fixed by upgrading
- Yes
Solution
Update feedparser to version 5.1.2 or higher.
Vulnerable code sample
import feedparser
# Sample XML with a crafted ENTITY declaration that could lead to memory consumption
xml_data = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE feed [
<!ENTITY xxe SYSTEM "file:///dev/random">
]>
<feed>
<title>Test Feed</title>
<entry>
<title>&xxe;</title>
<content>Some content</content>
</entry>
</feed>
"""
# Parse the potentially vulnerable XML
try:
feed = feedparser.parse(xml_data)
print(feed)
except Exception as e:
print(f"An error occurred: {e}")Patched code sample
import feedparser
import xml.sax.saxutils as saxutils
def safe_parse(feed_url):
# Use a custom parser that limits the depth of XML parsing
parser = feedparser.parse(feed_url, etag=None, modified=None, handler=None)
# Check for any potential XML ENTITY declarations
if '<!ENTITY' in parser.raw_data:
raise ValueError("Potentially dangerous XML ENTITY declaration detected.")
return parser
# Example usage
try:
feed = safe_parse("http://example.com/feed")
except ValueError as e:
print(e)Cite this entry
@misc{vaitp:cve20122921,
title = {{Python-feedparser < 5.1.2 Denial of service with crafted non-ASCII XML ENTITY in documents}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2012},
note = {VAITP Python Vulnerability Dataset, entry CVE-2012-2921},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2012-2921/}}
}
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 ::
