]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added a warning to the urljoin docs, indicating that it is not safe to use with attac...
authorAlex Gaynor <alex.gaynor@gmail.com>
Fri, 15 Nov 2024 23:09:05 +0000 (18:09 -0500)
committerGitHub <noreply@github.com>
Fri, 15 Nov 2024 23:09:05 +0000 (18:09 -0500)
This was flagged to me at a party today by someone who works in red-teaming as a frequently encountered footgun. Documenting the potentially unexpected behavior seemed like a good place to start.

Doc/library/urllib.parse.rst

index 0501dc8733b2cdf2d20346f3dfbebdf3cdbc074d..44a9c79cba22162475ae07a5a443330f64ffdbe8 100644 (file)
@@ -407,6 +407,15 @@ or on combining URL components into a URL string.
       If you do not want that behavior, preprocess the *url* with :func:`urlsplit` and
       :func:`urlunsplit`, removing possible *scheme* and *netloc* parts.
 
+   .. warning::
+
+      Because an absolute URL may be passed as the ``url`` parameter, it is
+      generally **not secure** to use ``urljoin`` with an attacker-controlled
+      ``url``. For example in,
+      ``urljoin("https://website.com/users/", username)``, if ``username`` can
+      contain an absolute URL, the result of ``urljoin`` will be the absolute
+      URL.
+
 
    .. versionchanged:: 3.5