CVE-2026-44307: Mako Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-2h4p-vjrc-8xpq
CWE-22
Published
Advisory Summary

CVE-2026-44307 is a HIGH path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Mako libraries in the PyPI ecosystem. The issue involves mako vulnerable to path traversal via backslash uri on windows in templatelookup. Remediation is available by upgrading affected packages to version 1.3.12.

CVE-2026-44307 at a Glance

CVE Identifier CVE-2026-44307
GHSA Identifier GHSA-2h4p-vjrc-8xpq
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Mako
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2026-44307

To remediate this vulnerability, upgrade all affected Mako dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

Mako fixed: 1.3.12
pip install Mako>=1.3.12
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show Mako

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-44307, inspect your installed packages using pip:

pip show Mako

Analyze the terminal output to locate any version of Mako in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.3.12), your application is affected.

Note: The pip show Mako command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Mako, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## 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()` uses `posixpath.normpath`/`posixpath.join` for path construction but `os.path.isfile()` for existence check - `mako/template.py`: `Template.__init__()` URI validation uses `os.path.normpath()` which on Windows resolves backslash traversal to a form that passes the `startswith("..")` 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.

CVE-2026-44307 Affected Mako Versions

1 component(s)
Fixed Versions:
1.3.12
Product / Package Ecosystem Affected Versions Fixed Version
Mako
PyPI
< 1.3.12
1.3.12

References

Frequently Asked Questions

What is CVE-2026-44307?
CVE-2026-44307 is a security vulnerability in Mako involving Mako vulnerable to path traversal via backslash URI on Windows in TemplateLookup under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Mako versions are affected?
Affected versions include releases prior to 1.3.12 across affected packages: Mako.
What version fixes CVE-2026-44307?
Upgrading to 1.3.12 (or the latest patched release for your respective branch) resolves the vulnerability.
Is Mako affected?
Yes, Mako is affected in releases prior to 1.3.12. Upgrade your dependency to 1.3.12 or later.
What CWE is associated with CVE-2026-44307?
CVE-2026-44307 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2026-44307?
Run the dependency tree command: 'pip show Mako'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-2h4p-vjrc-8xpq",
  "modified" : "2026-05-13T16:43:11Z",
  "published" : "2026-05-06T21:45:16Z",
  "aliases" : [ "CVE-2026-44307" ],
  "summary" : "Mako vulnerable to path traversal via backslash URI on Windows in TemplateLookup",
  "details" : "## Summary\n\nOn 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.\n\n\n## Details\n\nThe 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.\n\nThe vulnerability chain:\n\n1. `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.\n2. `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.\n3. `os.path.isfile()` on Windows interprets `\\` as a path separator, resolving the `..` traversal and finding files outside the template directory.\n\n### Affected code\n\n- `mako/lookup.py`: `TemplateLookup.get_template()` uses `posixpath.normpath`/`posixpath.join` for path construction but `os.path.isfile()` for existence check\n- `mako/template.py`: `Template.__init__()` URI validation uses `os.path.normpath()` which on Windows resolves backslash traversal to a form that passes the `startswith(\"..\")` guard\n\n## Impact\n\nIf 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.\n\n## Remediation\n\nThe fix should normalize backslashes to forward slashes early in the URI processing pipeline, before any path operations, to ensure consistent behavior across platforms.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "Mako"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.3.12"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.3.11"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/mako/security/advisories/GHSA-2h4p-vjrc-8xpq"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-44307"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/mako/issues/435"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/mako/commit/72e10c573ca0fbcbddd4455abca8ce92a61780d7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sqlalchemy/mako"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sqlalchemy/mako/releases/tag/rel_1_3_12"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-05-06T21:45:16Z",
    "nvd_published_at" : "2026-05-12T22:16:37Z"
  }
}