Skip to content

Commit c896210

Browse files
miss-islingtonalex
andauthored
[3.13] Added a warning to the urljoin docs, indicating that it is not safe to use with attacker controlled URLs (GH-126659) (#126888)
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 7be8743 commit c896210

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
@@ -403,6 +403,15 @@ or on combining URL components into a URL string.
403403
If you do not want that behavior, preprocess the *url* with :func:`urlsplit` and
404404
:func:`urlunsplit`, removing possible *scheme* and *netloc* parts.
405405

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

407416
.. versionchanged:: 3.5
408417

0 commit comments

Comments
 (0)