]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Added a warning to the urljoin docs, indicating that it is not safe to use...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 15 Nov 2024 23:17:37 +0000 (00:17 +0100)
committerGitHub <noreply@github.com>
Fri, 15 Nov 2024 23:17:37 +0000 (23:17 +0000)
Added a warning to the urljoin docs, indicating that it is not safe to use with attacker controlled URLs (GH-126659)

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.
(cherry picked from commit d6bcc154e93a0a20ab97187d3e8b726fffb14f8f)

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
Doc/library/urllib.parse.rst

index 27909b763e9e437be03a71093777a84e2e2706fe..b32b4af1aa84bf022ac1c5f0acfabfed841d233c 100644 (file)
@@ -395,6 +395,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