CVE-2026-61632
Path traversal in PyMdown's b64 extension allows arbitrary file disclosure.
- CVSS 5.3
- 22
- Input Validation and Sanitization
- Remote
PyMdown Extensions is a set of extensions for the Python-Markdown markdown project. In versions up to and including 10.21.3, the b64 extension is vulnerable to a path traversal that discloses arbitrary files: it inlines images referenced by <img src="…"> by joining the src onto the configured base_path with os.path.normpath and opening the result directly, without verifying that the resolved path stays inside base_path. As a result, an src containing ../ sequences or an absolute path reads a file outside base_path as long as it has an allowed image extension (.png, .jpg, .jpeg, .gif, .svg), and the file's contents are then base64-encoded into the rendered output, disclosing them. An application that renders untrusted Markdown with pymdownx.b64 enabled can therefore leak the contents of image-extension files readable by the process to whoever controls the Markdown or views the output, a targeted file-read bounded by the extension check. This issue has been fixed in version 11.0.
- CWE
- 22
- CVSS base score
- 5.3
- Published
- 2026-08-06
- OWASP
- A01 Broken Access Control
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- PyMdown Exte
- Fixed by upgrading
- Yes
Solution
Upgrade PyMdown Extensions to version 11.0 or later.
Vulnerable code sample
import os
import base64
from xml.etree import ElementTree
class B64Extension:
def __init__(self, base_path='.', allowed_exts=None):
self.base_path = os.path.abspath(base_path)
if allowed_exts is None:
self.allowed_exts = {'.png', '.jpg', '.jpeg', '.gif', '.svg'}
else:
self.allowed_exts = allowed_exts
def run(self, root: ElementTree.Element):
"""Iterate through the `root` and inline images."""
for el in root.iter():
if el.tag == 'img':
src = el.get('src')
if not src or src.startswith('data:'):
continue
ext = os.path.splitext(src)[1].lower()
if ext not in self.allowed_exts:
continue
# VULNERABLE: The path is normalized but not validated to be within the base_path, allowing directory traversal.
image_path = os.path.normpath(os.path.join(self.base_path, src))
try:
with open(image_path, "rb") as f:
encoded = base64.b64encode(f.read()).decode('ascii')
el.set('src', f"data:image/{ext[1:]};base64,{encoded}")
except OSError:
# Could not open the file, leave the src as is.
passPatched code sample
import os
import base64
from xml.etree import ElementTree
class B64Extension:
def __init__(self, base_path='.', allowed_exts=None):
self.base_path = os.path.abspath(base_path)
if allowed_exts is None:
self.allowed_exts = {'.png', '.jpg', '.jpeg', '.gif', '.svg'}
else:
self.allowed_exts = allowed_exts
def run(self, root: ElementTree.Element):
"""Iterate through the `root` and inline images."""
for el in root.iter():
if el.tag == 'img':
src = el.get('src')
if not src or src.startswith('data:'):
continue
ext = os.path.splitext(src)[1].lower()
if ext not in self.allowed_exts:
continue
image_path = os.path.normpath(os.path.join(self.base_path, src))
# FIX: Ensure the resolved path is within the configured base path directory.
if not os.path.abspath(image_path).startswith(self.base_path + os.sep):
continue
try:
with open(image_path, "rb") as f:
encoded = base64.b64encode(f.read()).decode('ascii')
el.set('src', f"data:image/{ext[1:]};base64,{encoded}")
except OSError:
# Could not open the file, leave the src as is.
passPayload
<img src="../../../../../../../etc/secrets.svg">
Cite this entry
@misc{vaitp:cve202661632,
title = {{Path traversal in PyMdown's b64 extension allows arbitrary file disclosure.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-61632},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-61632/}}
}
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 ::
