Skip to content

Commit d6bcc15

Browse files
authored
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.
1 parent 94a7a4e commit d6bcc15

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Doc/library/urllib.parse.rst

+9
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@ or on combining URL components into a URL string.
407407
If you do not want that behavior, preprocess the *url* with :func:`urlsplit` and
408408
:func:`urlunsplit`, removing possible *scheme* and *netloc* parts.
409409

410+
.. warning::
411+
412+
Because an absolute URL may be passed as the ``url`` parameter, it is
413+
generally **not secure** to use ``urljoin`` with an attacker-controlled
414+
``url``. For example in,
415+
``urljoin("https://website.com/users/", username)``, if ``username`` can
416+
contain an absolute URL, the result of ``urljoin`` will be the absolute
417+
URL.
418+
410419

411420
.. versionchanged:: 3.5
412421

0 commit comments

Comments
 (0)