CVE-2021-29421
Pikepdf 1.3.0 to 2.9.2: XXE in XMP metadata
- CVSS 7.5
- CWE-611 Improper Restriction of XML External Entity Reference
- Input Validation and Sanitization
- Remote
models/metadata.py in the pikepdf package 1.3.0 through 2.9.2 for Python allows XXE when parsing XMP metadata entries.
- CVSS base score
- 7.5
- Published
- 2021-04-01
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- pikepdf
- Fixed by upgrading
- Yes
Solution
Update pikepdf to version 2.9.3 or higher.
Vulnerable code sample
import xml.etree.ElementTree as ET
def vulnerable_parse_xmp(xmp_data):
return ET.fromstring(xmp_data)
# Example usage
xmp_data = """<xmpmeta>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://example.com">
<dc:title>Example Title</dc:title>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<dc:content>&xxe;</dc:content>
</rdf:Description>
</rdf:RDF>
</xmpmeta>"""
parsed_xmp = vulnerable_parse_xmp(xmp_data)
print(ET.tostring(parsed_xmp, pretty_print=True).decode())Patched code sample
import lxml.etree as ET
def safe_parse_xmp(xmp_data):
parser = ET.XMLParser(recover=False, no_network=True)
return ET.fromstring(xmp_data.encode('utf-8'), parser)
# Example usage
xmp_data = """<xmpmeta>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://example.com">
<dc:title>Example Title</dc:title>
</rdf:Description>
</rdf:RDF>
</xmpmeta>"""
try:
parsed_xmp = safe_parse_xmp(xmp_data)
print(ET.tostring(parsed_xmp, pretty_print=True).decode())
except ET.XMLSyntaxError as e:
print("Failed to parse XMP data:", e)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Fix XXE vulnerability in XMP metadata parsing (pikepdf/pikepdf)
src/pikepdf/models/metadata.py,src/pikepdf/models/metadata.py · PdfMetadata._load_from
Cite this entry
@misc{vaitp:cve202129421,
title = {{Pikepdf 1.3.0 to 2.9.2: XXE in XMP metadata}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-29421},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-29421/}}
}
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 ::
