Mako vulnerable to path traversal via backslash URI on Windows in TemplateLookup
Published 6 May 2026 · Updated 10 Sept 2026
Is your project on an affected mako?
Look after several Python apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- <1.3.12
- Fixed in
- 1.3.12
pip install 'mako>=1.3.12'Details
Summary
On Windows, a URI using backslash traversal (e.g. \..\..\ secret.txt) bypasses the directory traversal check in Template.__init__ and the posixpath-based normalization in TemplateLookup.get_template(), allowing reads of files outside the configured template directory.
Details
The root cause is a mismatch between posixpath (used for URI normalization in get_template()) and os.path (used for file access via os.path.isfile() and validation via os.path.normpath() in Template.__init__). On Windows, os.path is ntpath, which treats \ as a path separator, while posixpath treats it as a literal character.
The vulnerability chain:
1. get_template() strips only leading / via re.sub(r"^\/+", "", uri) and normalizes with posixpath — backslash \ is treated as a literal character, so \..\ secret.txt passes through with .. undetected.
2. Template.__init__() validation uses os.path.normpath() — on Windows this resolves \..\ secret.txt to \secret.txt, which does not start with .., so the startswith("..") check passes.
3. os.path.isfile() on Windows interprets \ as a path separator, resolving the .. traversal and finding files outside the template directory.
Affected code
mako/lookup.py:TemplateLookup.get_template()usesposixpath.normpath/posixpath.joinfor path construction butos.path.isfile()for existence checkmako/template.py:Template.__init__()URI validation usesos.path.normpath()which on Windows resolves backslash traversal to a form that passes thestartswith("..")guard
Impact
If an application passes user-controlled template names or include paths to TemplateLookup.get_template(), an attacker on Windows may be able to load and disclose readable files outside the configured template directory. The primary impact is local file disclosure. If the targeted file contains Mako/Python template syntax, it may also be parsed and executed as a template.
Remediation
The fix should normalize backslashes to forward slashes early in the URI processing pipeline, before any path operations, to ensure consistent behavior across platforms.
Is GHSA-2h4p-vjrc-8xpq in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected mako, and gives you the command that fixes it.
More advisories for mako
- MediumCVE-2026-102991Mako: Path traversal via drive-letter URI on Windows in TemplateLookup · 5 Oct 2026
- HighCVE-2026-41205Mako: Path traversal via double-slash URI prefix in TemplateLookup · 16 Apr 2026
- HighCVE-2022-40023mako is vulnerable to Regular Expression Denial of Service · 16 Sept 2022
- MediumCVE-2010-2480Mako contains Cross-site Scripting vulnerability · 17 May 2022
References
- Linkgithub.com/sqlalchemy/mako/security/advisories/GHSA-2h4p-vjrc-8xpq
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-44307
- Linkgithub.com/sqlalchemy/mako/issues/435
- Linkgithub.com/sqlalchemy/mako/commit/72e10c573ca0fbcbddd4455abca8ce92a61780d7
- Packagegithub.com/sqlalchemy/mako
- Linkgithub.com/sqlalchemy/mako/releases/tag/rel_1_3_12
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.