Skip to content

Commit c4b17db

Browse files
kovanclaude
andcommitted
gh-142412: Add warning about urlsplit's netloc parsing and open redirects
Add a warning to the URL parsing security section explaining that urlsplit/urlparse only parse the netloc when preceded by //. This behavior can lead to open redirect vulnerabilities if applications rely solely on checking the netloc to validate redirect URLs. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7e2c9bd commit c4b17db

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Doc/library/urllib.parse.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,17 @@ code before trusting a returned component part. Does that ``scheme`` make
530530
sense? Is that a sensible ``path``? Is there anything strange about that
531531
``hostname``? etc.
532532

533+
.. warning::
534+
535+
:func:`urlsplit` (and :func:`urlparse`) does not consider a URL's
536+
:attr:`~urllib.parse.SplitResult.netloc` to be present unless
537+
it is preceded by ``//``. This means that, for example, the URL
538+
``///example.com/path`` will be parsed with an empty ``netloc`` and a
539+
``path`` of ``/example.com/path``. This behavior may lead to open redirect
540+
vulnerabilities in applications that rely on checking the ``netloc`` to
541+
validate redirect URLs. Always carefully validate redirect targets,
542+
preferably using an allowlist of known-safe URLs or hosts.
543+
533544
What constitutes a URL is not universally well defined. Different applications
534545
have different needs and desired constraints. For instance the living `WHATWG
535546
spec`_ describes what user facing web clients such as a web browser require.

0 commit comments

Comments
 (0)