Skip to content

Commit

Permalink
Added a warning to the urljoin docs, indicating that it is not safe t…
Browse files Browse the repository at this point in the history
…o 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.
  • Loading branch information
alex authored Nov 15, 2024
1 parent 94a7a4e commit d6bcc15
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Doc/library/urllib.parse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d6bcc15

Please sign in to comment.