VYPR
Moderate severityNVD Advisory· Published Nov 29, 2025· Updated Dec 1, 2025

Werkzeug safe_join() allows Windows special device names

CVE-2025-66221

Description

Werkzeug is a comprehensive WSGI web application library. Prior to version 3.1.4, Werkzeug's safe_join function allows path segments with Windows device names. On Windows, there are special device names such as CON, AUX, etc that are implicitly present and readable in every directory. send_from_directory uses safe_join to safely serve files at user-specified paths under a directory. If the application is running on Windows, and the requested path ends with a special device name, the file will be opened successfully, but reading will hang indefinitely. This issue has been patched in version 3.1.4.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
werkzeugPyPI
< 3.1.43.1.4

Affected products

1

Patches

1
4b833376a45c

Merge commit from fork

https://github.com/pallets/werkzeugDavid LordNov 29, 2025via ghsa
4 files changed · +27 8
  • CHANGES.rst+3 0 modified
    @@ -5,6 +5,9 @@ Version 3.1.4
     
     Unreleased
     
    +-   ``safe_join`` on Windows does not allow special device names. This prevents
    +    reading from these when using `send_from_directory`. ``secure_filename``
    +    already prevented writing to these. :ghsa:`hgf8-39gv-g3f2`
     -   The debugger pin fails after 10 attempts instead of 11. :pr:`3020`
     -   The multipart form parser handles a ``\r\n`` sequence at a chunk boundary.
         :issue:`3065`
    
  • src/werkzeug/security.py+15 0 modified
    @@ -12,6 +12,14 @@
     _os_alt_seps: list[str] = list(
         sep for sep in [os.sep, os.path.altsep] if sep is not None and sep != "/"
     )
    +_windows_device_files = {
    +    "CON",
    +    "PRN",
    +    "AUX",
    +    "NUL",
    +    *(f"COM{i}" for i in range(10)),
    +    *(f"LPT{i}" for i in range(10)),
    +}
     
     
     def gen_salt(length: int) -> str:
    @@ -139,6 +147,9 @@ def safe_join(directory: str, *pathnames: str) -> str | None:
         :param pathnames: The untrusted path components relative to the
             base directory.
         :return: A safe path, otherwise ``None``.
    +
    +    .. versionchanged:: 3.1.4
    +        Special device names are disallowed on Windows.
         """
         if not directory:
             # Ensure we end up with ./path if directory="" is given,
    @@ -153,6 +164,10 @@ def safe_join(directory: str, *pathnames: str) -> str | None:
     
             if (
                 any(sep in filename for sep in _os_alt_seps)
    +            or (
    +                os.name == "nt"
    +                and os.path.splitext(filename)[0].upper() in _windows_device_files
    +            )
                 or os.path.isabs(filename)
                 # ntpath.isabs doesn't catch this on Python < 3.11
                 or filename.startswith("/")
    
  • src/werkzeug/utils.py+1 8 modified
    @@ -21,6 +21,7 @@
     from .datastructures import Headers
     from .exceptions import NotFound
     from .exceptions import RequestedRangeNotSatisfiable
    +from .security import _windows_device_files
     from .security import safe_join
     from .wsgi import wrap_file
     
    @@ -34,14 +35,6 @@
     
     _entity_re = re.compile(r"&([^;]+);")
     _filename_ascii_strip_re = re.compile(r"[^A-Za-z0-9_.-]")
    -_windows_device_files = {
    -    "CON",
    -    "PRN",
    -    "AUX",
    -    "NUL",
    -    *(f"COM{i}" for i in range(10)),
    -    *(f"LPT{i}" for i in range(10)),
    -}
     
     
     class cached_property(property, t.Generic[_T]):
    
  • tests/test_security.py+8 0 modified
    @@ -70,3 +70,11 @@ def test_safe_join_os_sep():
     
     def test_safe_join_empty_trusted():
         assert safe_join("", "c:test.txt") == "./c:test.txt"
    +
    +
    +def test_safe_join_windows_special(monkeypatch: pytest.MonkeyPatch) -> None:
    +    """Windows special device name is not allowed on Windows."""
    +    monkeypatch.setattr("os.name", "nt")
    +    assert safe_join("a", "CON") is None
    +    monkeypatch.setattr("os.name", "posix")
    +    assert safe_join("a", "CON") == "a/CON"
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.