Skip to content

Commit 797a632

Browse files
miss-islingtonalex
andauthored
[3.12] Added a warning to the urljoin docs, indicating that it is not safe to use with attacker controlled URLs (GH-126659) (#126889)
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 d6bcc15) Co-authored-by: Alex Gaynor <[email protected]>
1 parent d0d892f commit 797a632

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Doc/library/urllib.parse.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ or on combining URL components into a URL string.
395395
If you do not want that behavior, preprocess the *url* with :func:`urlsplit` and
396396
:func:`urlunsplit`, removing possible *scheme* and *netloc* parts.
397397

398+
.. warning::
399+
400+
Because an absolute URL may be passed as the ``url`` parameter, it is
401+
generally **not secure** to use ``urljoin`` with an attacker-controlled
402+
``url``. For example in,
403+
``urljoin("https://website.com/users/", username)``, if ``username`` can
404+
contain an absolute URL, the result of ``urljoin`` will be the absolute
405+
URL.
406+
398407

399408
.. versionchanged:: 3.5
400409

0 commit comments

Comments
 (0)