CVE-2026-102991
Path traversal via mismatched Windows path handling in Mako template lookup.
- CVSS 6.5
- CWE-22
- Input Validation and Sanitization
- Remote
Mako is a template library written in Python. Prior to 1.4.2, on Windows, TemplateLookup.get_template() in mako/lookup.py resolves template URIs with posixpath, while Template.__init__() in mako/template.py validates them with os.path, which uses ntpath. A URI beginning with a drive designator causes ntpath to absorb the traversal segments before the leading dot-dot check, while posixpath resolution can escape the configured template directory. An application that passes attacker-controlled template names or include paths can disclose process-readable files on the same volume, and a targeted file containing Mako template syntax may also be parsed and executed as a template. Raw URL paths are generally normalized before reaching this form, but query strings, form or JSON bodies, route parameters, and dynamic include expressions can preserve it. This issue is fixed in version 1.4.2.
- CWE
- CWE-22
- CVSS base score
- 6.5
- Published
- 2026-09-30
- 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
- Mako
- Fixed by upgrading
- Yes
Solution
Upgrade Mako to version 1.4.2 or later.
Vulnerable code sample
import os
import posixpath
class TemplateLoader:
def __init__(self, base_dir):
self.base_dir = base_dir
def get_template(self, uri):
# VULNERABLE: using posixpath allows ".." traversal on Windows
safe_uri = posixpath.normpath(uri)
full_path = os.path.join(self.base_dir, safe_uri)
if not os.path.isfile(full_path):
raise FileNotFoundError(uri)
with open(full_path, 'r', encoding='utf-8') as f:
return f.read()Patched code sample
import os
class TemplateLoader:
def __init__(self, base_dir):
self.base_dir = base_dir
def get_template(self, uri):
# FIX: use os.path.normpath to respect Windows path semantics
safe_uri = os.path.normpath(uri)
full_path = os.path.join(self.base_dir, safe_uri)
if not os.path.isfile(full_path):
raise FileNotFoundError(uri)
with open(full_path, 'r', encoding='utf-8') as f:
return f.read()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 path traversal via drive designator URI on Windows in TemplateLookup (sqlalchemy/mako)
mako/template.py,mako/template.py · Template.__init__
Cite this entry
@misc{vaitp:cve2026102991,
title = {{Path traversal via mismatched Windows path handling in Mako template lookup.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-102991},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-102991/}}
}
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 ::
