GitHub advisory · PyPI
Mako: Path traversal via drive-letter URI on Windows in TemplateLookup
Description
On Windows, a TemplateLookup URI beginning with a drive designator (e.g. C:/../../secret.txt or C:\..\..\secret.txt) bypasses the directory traversal check in Template.__init__, allowing reads of files outside the configured template directory.
This is a third, independent instance of the root cause behind CVE-2026-41205 (the // prefix) and CVE-2026-44307 (the backslash form). Both of those fixes normalized a separator spelling. Neither addressed the other way posixpath and ntpath disagree: the drive designator. Both prior fixes remain effective on their own terms; this variant survives them for an independent reason.
The root cause is the same posixpath / os.path mismatch: resolution is done with posixpath, confinement is checked with os.path, which is ntpath on Windows.
# mako/lookup.py -- resolution
247: srcfile = posixpath.normpath(posixpath.join(dir_, u)) # posixpath, always
248: if os.path.isfile(srcfile): # ntpath on Windows
# mako/template.py -- confinement
268: u_norm = os.path.normpath(u_norm) # ntpath on Windows
269: if u_norm.startswith(".."): # never true for a drive URI
posixpath has no concept of a drive, so it treats C: as an ordinary path component; the .. segments pop C: and then escape the template root. ntpath, by contrast, splits the drive off and treats the remainder as rooted, discarding the .. entirely -- so the guard on line 269 inspects a string from which the evidence has already been removed:
| URI | ntpath.normpath (what the guard sees) | guard fires |
|---|---|---|
| //../secret.txt | ..\secret.txt | yes |
| \..\secret.txt | ..\secret.txt | yes |
| C:/../../secret.txt | C:\secret.txt | no |
Because the guard cannot fire for any URI beginning with a single-letter drive designator, the traversal is unconstrained, and its depth does not have to be guessed.…
Manual fix · PyPI
pip install --upgrade "Mako>=1.4.2"Sources