CVE-2026-46338: Pymdown extensions Path Traversal Vulnerability
MODERATECVE-2026-46338 is a MODERATE (CVSS 4.3) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Pymdown extensions libraries in the PyPI ecosystem. The issue involves regression in pymdownx.snippets reintroduces sibling-prefix path traversal bypass despite restrict_base_path. Remediation is available by upgrading affected packages to version 10.21.3.
CVE-2026-46338 at a Glance
Security Impact
CVSS: 4.3
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N).
How to Fix CVE-2026-46338
To remediate this vulnerability, upgrade all affected Pymdown extensions dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install pymdown-extensions>=10.21.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show pymdown-extensions
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2026-46338, inspect your installed packages using pip:
pip show pymdown-extensions
Analyze the terminal output to locate any version of Pymdown extensions in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 10.21.3), your application is affected.
Note: The pip show pymdown-extensions 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 Pymdown extensions, 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
CVE-2026-46338 Affected Pymdown extensions Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
pymdown-extensions
|
PyPI |
≥ 10.0.1
< 10.21.3
|
10.21.3
|
References
Frequently Asked Questions
What is CVE-2026-46338?
Which Pymdown extensions versions are affected?
What version fixes CVE-2026-46338?
Is pymdown-extensions affected?
What is the CVSS score of CVE-2026-46338?
What CWE is associated with CVE-2026-46338?
How can I check PyPI dependencies for CVE-2026-46338?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-62q4-447f-wv8h",
"modified" : "2026-05-19T20:00:29Z",
"published" : "2026-05-19T20:00:29Z",
"aliases" : [ "CVE-2026-46338" ],
"summary" : "Regression in pymdownx.snippets reintroduces sibling-prefix path traversal bypass despite restrict_base_path",
"details" : "# Summary\n\n`pymdownx.snippets` has a regression of the CVE-2023-32309 / GHSA-jh85-wwv9-24hv fix. With `restrict_base_path: True` (the default), the current `filename.startswith(base)` containment check does not enforce a directory boundary. As a result, a markdown snippet directive can read files from sibling paths that share the same prefix as `base_path`, such as `docs` vs `docs_internal`.\n\nThe regression was introduced in PR #2039 / commit `7c13bda5b7793b172efd1abb6712e156a83fe07d`, which replaced the original directory-identity check with a plain string-prefix comparison.\n\n# Details\n\nThe regression was introduced in commit `7c13bda5b7793b172efd1abb6712e156a83fe07d` (2023-05-15, #2039 *\"Fix regression of snippets nested deeply under specified base path\"*), which relaxed the original `os.path.samefile(base, os.path.dirname(filename))` check to a plain `startswith(base)`.\n\n`SnippetPreprocessor.get_snippet_path()` in `pymdownx/snippets.py`:\n\n```python\nif self.restrict_base_path:\n filename = os.path.abspath(os.path.join(base, path))\n # If the absolute path is no longer under the specified base path, reject the file\n if not filename.startswith(base):\n continue\n```\n\n`base` is `os.path.abspath(b)` and has no trailing separator. `str.startswith(base)` is `True` for any `filename` whose string representation begins with the same characters as `base`, regardless of whether those characters end at a directory boundary.\n\nConcrete example:\n\n* `base = \"/x/docs\"`\n* `path = \"../docs_secret/leak.txt\"` (inside the markdown snippet directive)\n* `os.path.join(base, path)` → `\"/x/docs/../docs_secret/leak.txt\"`\n* `os.path.abspath(...)` → `\"/x/docs_secret/leak.txt\"`\n* `filename.startswith(base)` → `True`, because `\"/x/docs_secret/...\"` begins with the literal string `\"/x/docs\"`.\n\nAll releases from **10.0.1 (2023-05-15) through 10.21.2 (current)** are affected.\n\n# Impact\n\nArbitrary file read within the host the build runs on, bounded by the prefix match. With `base_path = /x/docs` the attacker can read files from any sibling directory whose path begins with the literal string `/x/docs` followed by any non-separator character — for example `/x/docs_internal/`, `/x/docs.bak/`, `/x/docs2/`.\n\nThe threat model is the same as the original CVE-2023-32309: markdown content processed by the snippets preprocessor in a build pipeline (typical scenario: an MkDocs documentation site built in CI from PR contributions or otherwise less-trusted markdown) can read files outside the configured base. CI builds that publish the generated HTML expose the read file to the public; CI builds with secrets on disk leak those secrets.\n\n# Reproduction\n\nMinimal local PoC, non-destructive:\n\n```python\nimport os, shutil, tempfile, markdown\n\nwork = tempfile.mkdtemp(prefix=\"pmx_poc_\")\ntry:\n base = os.path.join(work, \"docs\")\n sibling = os.path.join(work, \"docs_secret\")\n os.makedirs(base)\n os.makedirs(sibling)\n with open(os.path.join(sibling, \"leak.txt\"), \"w\") as f:\n f.write(\"TOP_SECRET_FROM_SIBLING_DIR\\n\")\n\n out = markdown.markdown(\n '--8<-- \"../docs_secret/leak.txt\"\\n',\n extensions=[\"pymdownx.snippets\"],\n extension_configs={\n \"pymdownx.snippets\": {\n \"base_path\": [base],\n \"restrict_base_path\": True,\n \"check_paths\": True,\n }\n },\n )\n print(out) # -> <p>TOP_SECRET_FROM_SIBLING_DIR</p>\nfinally:\n shutil.rmtree(work)\n```\n\nDefault `restrict_base_path: True` is sufficient — no non-default option is required.\n\n# Suggested fix\n\nMinimal change — require the separator after the base prefix:\n\n```diff\n- if not filename.startswith(base):\n+ # Append `os.sep` so a sibling directory whose name shares a prefix\n+ # (e.g. `/x/docs` vs `/x/docs_evil`) cannot satisfy the check.\n+ if not filename.startswith(base + os.sep):\n continue\n```\n\nThis preserves the original intent (allow snippets nested at any depth under `base_path`) while restoring the directory-boundary check. It does not affect the `os.path.isdir(base)` branch where `base` is a file (that branch still uses `os.path.samefile`).\n\nAlternative: `os.path.commonpath([base, filename]) == base` is equivalent and slightly more idiomatic, though it raises `ValueError` on different drives on Windows and would need a `try/except`. The `startswith(base + os.sep)` fix is the smaller diff.\n\nNote: this fix does not change behaviour for symlinks inside `base_path`. The existing implementation uses `os.path.abspath` (not `os.path.realpath`), so a symlink within `base_path` pointing outside is still followed. That is a separate concern — symlinks require write access to `base_path`, a much higher bar than the current bypass — and matches the behaviour the CVE-2023 fix established.\n\n# Regression test\n\nA regression test class `TestSnippetsSiblingPrefix` was added in `tests/test_extensions/test_snippets.py`. It uses `tests/test_extensions/_snippets/nested` as `base_path` and a new fixture directory `tests/test_extensions/_snippets/nested_sibling_evil/leak.txt`. It asserts that the markdown directive `--8<-- \"../nested_sibling_evil/leak.txt\"` raises `SnippetMissingError`.\n\n* Without fix: test fails (`AssertionError: SnippetMissingError not raised`, sibling file is silently read).\n* With fix: test passes.\n\nFull suite: `python -m pytest tests/ -q` → **738 passed** (737 baseline + 1 new regression test). No regressions.\n\n# Affected versions\n\n`>= 10.0.1, <= 10.21.2`",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "pymdown-extensions"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "10.0.1"
}, {
"fixed" : "10.21.3"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 10.21.2"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/facelessuser/pymdown-extensions/security/advisories/GHSA-62q4-447f-wv8h"
}, {
"type" : "WEB",
"url" : "https://github.com/facelessuser/pymdown-extensions/pull/2039"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/facelessuser/pymdown-extensions"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-22" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-05-19T20:00:29Z",
"nvd_published_at" : null
}
}