VYPR
Moderate severityNVD Advisory· Published Oct 17, 2023· Updated Nov 3, 2025

Request body not stripped after redirect in urllib3

CVE-2023-45803

Description

urllib3 is a user-friendly HTTP client library for Python. urllib3 previously wouldn't remove the HTTP request body when an HTTP redirect response using status 301, 302, or 303 after the request had its method changed from one that could accept a request body (like POST) to GET as is required by HTTP RFCs. Although this behavior is not specified in the section for redirects, it can be inferred by piecing together information from different sections and we have observed the behavior in other major HTTP client implementations like curl and web browsers. Because the vulnerability requires a previously trusted service to become compromised in order to have an impact on confidentiality we believe the exploitability of this vulnerability is low. Additionally, many users aren't putting sensitive data in HTTP request bodies, if this is the case then this vulnerability isn't exploitable. Both of the following conditions must be true to be affected by this vulnerability: 1. Using urllib3 and submitting sensitive information in the HTTP request body (such as form data or JSON) and 2. The origin service is compromised and starts redirecting using 301, 302, or 303 to a malicious peer or the redirected-to service becomes compromised. This issue has been addressed in versions 1.26.18 and 2.0.7 and users are advised to update to resolve this issue. Users unable to update should disable redirects for services that aren't expecting to respond with redirects with redirects=False and disable automatic redirects with redirects=False and handle 301, 302, and 303 redirects manually by stripping the HTTP request body.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
urllib3PyPI
>= 2.0.0, < 2.0.72.0.7
urllib3PyPI
< 1.26.181.26.18

Affected products

1

Patches

3
4e98d57809da

Bring 2.0.7 & 1.26.18 to main (#3161)

https://github.com/urllib3/urllib3Illia VolochiiOct 17, 2023via ghsa
9 files changed · +73 4
  • CHANGES.rst+10 0 modified
    @@ -1,3 +1,8 @@
    +2.0.7 (2023-10-17)
    +==================
    +
    +* Made body stripped from HTTP requests changing the request method to GET after HTTP 303 "See Other" redirect responses.
    +
     2.0.6 (2023-10-02)
     ==================
     
    @@ -167,6 +172,11 @@ Fixed
     * Fixed a socket leak if ``HTTPConnection.connect()`` fails (`#2571 <https://github.com/urllib3/urllib3/pull/2571>`__).
     * Fixed ``urllib3.contrib.pyopenssl.WrappedSocket`` and ``urllib3.contrib.securetransport.WrappedSocket`` close methods (`#2970 <https://github.com/urllib3/urllib3/issues/2970>`__)
     
    +1.26.18 (2023-10-17)
    +====================
    +
    +* Made body stripped from HTTP requests changing the request method to GET after HTTP 303 "See Other" redirect responses.
    +
     1.26.17 (2023-10-02)
     ====================
     
    
  • dummyserver/handlers.py+6 0 modified
    @@ -281,6 +281,12 @@ def encodingrequest(self, request: httputil.HTTPServerRequest) -> Response:
         def headers(self, request: httputil.HTTPServerRequest) -> Response:
             return Response(json.dumps(dict(request.headers)))
     
    +    def headers_and_params(self, request: httputil.HTTPServerRequest) -> Response:
    +        params = request_params(request)
    +        return Response(
    +            json.dumps({"headers": dict(request.headers), "params": params})
    +        )
    +
         def multi_headers(self, request: httputil.HTTPServerRequest) -> Response:
             return Response(json.dumps({"headers": list(request.headers.get_all())}))
     
    
  • .readthedocs.yml+1 1 modified
    @@ -3,7 +3,7 @@ version: 2
     build:
       os: ubuntu-22.04
       tools:
    -    python: "3"
    +    python: "3.11"
     
     python:
       install:
    
  • src/urllib3/_collections.py+20 0 modified
    @@ -10,6 +10,8 @@
         # dependency, and is not available at runtime.
         from typing import Protocol
     
    +    from typing_extensions import Self
    +
         class HasGettableStringKeys(Protocol):
             def keys(self) -> typing.Iterator[str]:
                 ...
    @@ -391,6 +393,24 @@ def getlist(
                 # meets our external interface requirement of `Union[List[str], _DT]`.
                 return vals[1:]
     
    +    def _prepare_for_method_change(self) -> Self:
    +        """
    +        Remove content-specific header fields before changing the request
    +        method to GET or HEAD according to RFC 9110, Section 15.4.
    +        """
    +        content_specific_headers = [
    +            "Content-Encoding",
    +            "Content-Language",
    +            "Content-Location",
    +            "Content-Type",
    +            "Content-Length",
    +            "Digest",
    +            "Last-Modified",
    +        ]
    +        for header in content_specific_headers:
    +            self.discard(header)
    +        return self
    +
         # Backwards compatibility for httplib
         getheaders = getlist
         getallmatchingheaders = getlist
    
  • src/urllib3/connectionpool.py+5 0 modified
    @@ -11,6 +11,7 @@
     from types import TracebackType
     
     from ._base_connection import _TYPE_BODY
    +from ._collections import HTTPHeaderDict
     from ._request_methods import RequestMethods
     from .connection import (
         BaseSSLError,
    @@ -892,7 +893,11 @@ def urlopen(  # type: ignore[override]
             redirect_location = redirect and response.get_redirect_location()
             if redirect_location:
                 if response.status == 303:
    +                # Change the method according to RFC 9110, Section 15.4.4.
                     method = "GET"
    +                # And lose the body not to transfer anything sensitive.
    +                body = None
    +                headers = HTTPHeaderDict(headers)._prepare_for_method_change()
     
                 try:
                     retries = retries.increment(method, url, response=response, _pool=self)
    
  • src/urllib3/poolmanager.py+5 2 modified
    @@ -7,7 +7,7 @@
     from types import TracebackType
     from urllib.parse import urljoin
     
    -from ._collections import RecentlyUsedContainer
    +from ._collections import HTTPHeaderDict, RecentlyUsedContainer
     from ._request_methods import RequestMethods
     from .connection import ProxyConfig
     from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, port_by_scheme
    @@ -448,9 +448,12 @@ def urlopen(  # type: ignore[override]
             # Support relative URLs for redirecting.
             redirect_location = urljoin(url, redirect_location)
     
    -        # RFC 7231, Section 6.4.4
             if response.status == 303:
    +            # Change the method according to RFC 9110, Section 15.4.4.
                 method = "GET"
    +            # And lose the body not to transfer anything sensitive.
    +            kw["body"] = None
    +            kw["headers"] = HTTPHeaderDict(kw["headers"])._prepare_for_method_change()
     
             retries = kw.get("retries")
             if not isinstance(retries, Retry):
    
  • src/urllib3/_version.py+1 1 modified
    @@ -1,4 +1,4 @@
     # This file is protected via CODEOWNERS
     from __future__ import annotations
     
    -__version__ = "2.0.6"
    +__version__ = "2.0.7"
    
  • test/with_dummyserver/test_connectionpool.py+11 0 modified
    @@ -480,6 +480,17 @@ def test_redirect(self) -> None:
                 assert r.status == 200
                 assert r.data == b"Dummy server!"
     
    +    def test_303_redirect_makes_request_lose_body(self) -> None:
    +        with HTTPConnectionPool(self.host, self.port) as pool:
    +            response = pool.request(
    +                "POST",
    +                "/redirect",
    +                fields={"target": "/headers_and_params", "status": "303 See Other"},
    +            )
    +        data = response.json()
    +        assert data["params"] == {}
    +        assert "Content-Type" not in HTTPHeaderDict(data["headers"])
    +
         def test_bad_connect(self) -> None:
             with HTTPConnectionPool("badhost.invalid", self.port) as pool:
                 with pytest.raises(MaxRetryError) as e:
    
  • test/with_dummyserver/test_poolmanager.py+14 0 modified
    @@ -244,6 +244,20 @@ def test_redirect_without_preload_releases_connection(self) -> None:
                 assert r._pool.num_connections == 1
                 assert len(http.pools) == 1
     
    +    def test_303_redirect_makes_request_lose_body(self) -> None:
    +        with PoolManager() as http:
    +            response = http.request(
    +                "POST",
    +                f"{self.base_url}/redirect",
    +                fields={
    +                    "target": f"{self.base_url}/headers_and_params",
    +                    "status": "303 See Other",
    +                },
    +            )
    +        data = response.json()
    +        assert data["params"] == {}
    +        assert "Content-Type" not in HTTPHeaderDict(data["headers"])
    +
         def test_unknown_scheme(self) -> None:
             with PoolManager() as http:
                 unknown_scheme = "unknown"
    
b594c5ceaca3

Merge pull request from GHSA-g4mx-q9vg-27p4

https://github.com/urllib3/urllib3Illia VolochiiOct 17, 2023via ghsa
6 files changed · +61 2
  • dummyserver/handlers.py+7 0 modified
    @@ -186,6 +186,8 @@ def redirect(self, request):
             status = request.params.get("status", "303 See Other")
             if len(status) == 3:
                 status = "%s Redirect" % status.decode("latin-1")
    +        elif isinstance(status, bytes):
    +            status = status.decode("latin-1")
     
             headers = [("Location", target)]
             return Response(status=status, headers=headers)
    @@ -264,6 +266,11 @@ def encodingrequest(self, request):
         def headers(self, request):
             return Response(json.dumps(dict(request.headers)))
     
    +    def headers_and_params(self, request):
    +        return Response(
    +            json.dumps({"headers": dict(request.headers), "params": request.params})
    +        )
    +
         def successful_retry(self, request):
             """Handler which will return an error and then success
     
    
  • src/urllib3/_collections.py+18 0 modified
    @@ -268,6 +268,24 @@ def getlist(self, key, default=__marker):
             else:
                 return vals[1:]
     
    +    def _prepare_for_method_change(self):
    +        """
    +        Remove content-specific header fields before changing the request
    +        method to GET or HEAD according to RFC 9110, Section 15.4.
    +        """
    +        content_specific_headers = [
    +            "Content-Encoding",
    +            "Content-Language",
    +            "Content-Location",
    +            "Content-Type",
    +            "Content-Length",
    +            "Digest",
    +            "Last-Modified",
    +        ]
    +        for header in content_specific_headers:
    +            self.discard(header)
    +        return self
    +
         # Backwards compatibility for httplib
         getheaders = getlist
         getallmatchingheaders = getlist
    
  • src/urllib3/connectionpool.py+5 0 modified
    @@ -9,6 +9,7 @@
     from socket import error as SocketError
     from socket import timeout as SocketTimeout
     
    +from ._collections import HTTPHeaderDict
     from .connection import (
         BaseSSLError,
         BrokenPipeError,
    @@ -843,7 +844,11 @@ def _is_ssl_error_message_from_http_proxy(ssl_error):
             redirect_location = redirect and response.get_redirect_location()
             if redirect_location:
                 if response.status == 303:
    +                # Change the method according to RFC 9110, Section 15.4.4.
                     method = "GET"
    +                # And lose the body not to transfer anything sensitive.
    +                body = None
    +                headers = HTTPHeaderDict(headers)._prepare_for_method_change()
     
                 try:
                     retries = retries.increment(method, url, response=response, _pool=self)
    
  • src/urllib3/poolmanager.py+5 2 modified
    @@ -4,7 +4,7 @@
     import functools
     import logging
     
    -from ._collections import RecentlyUsedContainer
    +from ._collections import HTTPHeaderDict, RecentlyUsedContainer
     from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, port_by_scheme
     from .exceptions import (
         LocationValueError,
    @@ -382,9 +382,12 @@ def urlopen(self, method, url, redirect=True, **kw):
             # Support relative URLs for redirecting.
             redirect_location = urljoin(url, redirect_location)
     
    -        # RFC 7231, Section 6.4.4
             if response.status == 303:
    +            # Change the method according to RFC 9110, Section 15.4.4.
                 method = "GET"
    +            # And lose the body not to transfer anything sensitive.
    +            kw["body"] = None
    +            kw["headers"] = HTTPHeaderDict(kw["headers"])._prepare_for_method_change()
     
             retries = kw.get("retries")
             if not isinstance(retries, Retry):
    
  • test/with_dummyserver/test_connectionpool.py+11 0 modified
    @@ -464,6 +464,17 @@ def test_redirect(self):
                 assert r.status == 200
                 assert r.data == b"Dummy server!"
     
    +    def test_303_redirect_makes_request_lose_body(self):
    +        with HTTPConnectionPool(self.host, self.port) as pool:
    +            response = pool.request(
    +                "POST",
    +                "/redirect",
    +                fields={"target": "/headers_and_params", "status": "303 See Other"},
    +            )
    +        data = json.loads(response.data)
    +        assert data["params"] == {}
    +        assert "Content-Type" not in HTTPHeaderDict(data["headers"])
    +
         def test_bad_connect(self):
             with HTTPConnectionPool("badhost.invalid", self.port) as pool:
                 with pytest.raises(MaxRetryError) as e:
    
  • test/with_dummyserver/test_poolmanager.py+15 0 modified
    @@ -5,6 +5,7 @@
     
     from dummyserver.server import HAS_IPV6
     from dummyserver.testcase import HTTPDummyServerTestCase, IPv6HTTPDummyServerTestCase
    +from urllib3._collections import HTTPHeaderDict
     from urllib3.connectionpool import port_by_scheme
     from urllib3.exceptions import MaxRetryError, URLSchemeUnknown
     from urllib3.poolmanager import PoolManager
    @@ -236,6 +237,20 @@ def test_redirect_without_preload_releases_connection(self):
                 assert r._pool.num_connections == 1
                 assert len(http.pools) == 1
     
    +    def test_303_redirect_makes_request_lose_body(self):
    +        with PoolManager() as http:
    +            response = http.request(
    +                "POST",
    +                "%s/redirect" % self.base_url,
    +                fields={
    +                    "target": "%s/headers_and_params" % self.base_url,
    +                    "status": "303 See Other",
    +                },
    +            )
    +        data = json.loads(response.data)
    +        assert data["params"] == {}
    +        assert "Content-Type" not in HTTPHeaderDict(data["headers"])
    +
         def test_unknown_scheme(self):
             with PoolManager() as http:
                 unknown_scheme = "unknown"
    
4e50fbc5db74

Merge pull request from GHSA-g4mx-q9vg-27p4

https://github.com/urllib3/urllib3Illia VolochiiOct 17, 2023via ghsa
6 files changed · +60 3
  • dummyserver/handlers.py+6 0 modified
    @@ -281,6 +281,12 @@ def encodingrequest(self, request: httputil.HTTPServerRequest) -> Response:
         def headers(self, request: httputil.HTTPServerRequest) -> Response:
             return Response(json.dumps(dict(request.headers)))
     
    +    def headers_and_params(self, request: httputil.HTTPServerRequest) -> Response:
    +        params = request_params(request)
    +        return Response(
    +            json.dumps({"headers": dict(request.headers), "params": params})
    +        )
    +
         def multi_headers(self, request: httputil.HTTPServerRequest) -> Response:
             return Response(json.dumps({"headers": list(request.headers.get_all())}))
     
    
  • src/urllib3/_collections.py+19 1 modified
    @@ -8,7 +8,7 @@
     if typing.TYPE_CHECKING:
         # We can only import Protocol if TYPE_CHECKING because it's a development
         # dependency, and is not available at runtime.
    -    from typing_extensions import Protocol
    +    from typing_extensions import Protocol, Self
     
         class HasGettableStringKeys(Protocol):
             def keys(self) -> typing.Iterator[str]:
    @@ -391,6 +391,24 @@ def getlist(
                 # meets our external interface requirement of `Union[List[str], _DT]`.
                 return vals[1:]
     
    +    def _prepare_for_method_change(self) -> Self:
    +        """
    +        Remove content-specific header fields before changing the request
    +        method to GET or HEAD according to RFC 9110, Section 15.4.
    +        """
    +        content_specific_headers = [
    +            "Content-Encoding",
    +            "Content-Language",
    +            "Content-Location",
    +            "Content-Type",
    +            "Content-Length",
    +            "Digest",
    +            "Last-Modified",
    +        ]
    +        for header in content_specific_headers:
    +            self.discard(header)
    +        return self
    +
         # Backwards compatibility for httplib
         getheaders = getlist
         getallmatchingheaders = getlist
    
  • src/urllib3/connectionpool.py+5 0 modified
    @@ -11,6 +11,7 @@
     from types import TracebackType
     
     from ._base_connection import _TYPE_BODY
    +from ._collections import HTTPHeaderDict
     from ._request_methods import RequestMethods
     from .connection import (
         BaseSSLError,
    @@ -893,7 +894,11 @@ def urlopen(  # type: ignore[override]
             redirect_location = redirect and response.get_redirect_location()
             if redirect_location:
                 if response.status == 303:
    +                # Change the method according to RFC 9110, Section 15.4.4.
                     method = "GET"
    +                # And lose the body not to transfer anything sensitive.
    +                body = None
    +                headers = HTTPHeaderDict(headers)._prepare_for_method_change()
     
                 try:
                     retries = retries.increment(method, url, response=response, _pool=self)
    
  • src/urllib3/poolmanager.py+5 2 modified
    @@ -7,7 +7,7 @@
     from types import TracebackType
     from urllib.parse import urljoin
     
    -from ._collections import RecentlyUsedContainer
    +from ._collections import HTTPHeaderDict, RecentlyUsedContainer
     from ._request_methods import RequestMethods
     from .connection import ProxyConfig
     from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, port_by_scheme
    @@ -449,9 +449,12 @@ def urlopen(  # type: ignore[override]
             # Support relative URLs for redirecting.
             redirect_location = urljoin(url, redirect_location)
     
    -        # RFC 7231, Section 6.4.4
             if response.status == 303:
    +            # Change the method according to RFC 9110, Section 15.4.4.
                 method = "GET"
    +            # And lose the body not to transfer anything sensitive.
    +            kw["body"] = None
    +            kw["headers"] = HTTPHeaderDict(kw["headers"])._prepare_for_method_change()
     
             retries = kw.get("retries")
             if not isinstance(retries, Retry):
    
  • test/with_dummyserver/test_connectionpool.py+11 0 modified
    @@ -480,6 +480,17 @@ def test_redirect(self) -> None:
                 assert r.status == 200
                 assert r.data == b"Dummy server!"
     
    +    def test_303_redirect_makes_request_lose_body(self) -> None:
    +        with HTTPConnectionPool(self.host, self.port) as pool:
    +            response = pool.request(
    +                "POST",
    +                "/redirect",
    +                fields={"target": "/headers_and_params", "status": "303 See Other"},
    +            )
    +        data = response.json()
    +        assert data["params"] == {}
    +        assert "Content-Type" not in HTTPHeaderDict(data["headers"])
    +
         def test_bad_connect(self) -> None:
             with HTTPConnectionPool("badhost.invalid", self.port) as pool:
                 with pytest.raises(MaxRetryError) as e:
    
  • test/with_dummyserver/test_poolmanager.py+14 0 modified
    @@ -244,6 +244,20 @@ def test_redirect_without_preload_releases_connection(self) -> None:
                 assert r._pool.num_connections == 1
                 assert len(http.pools) == 1
     
    +    def test_303_redirect_makes_request_lose_body(self) -> None:
    +        with PoolManager() as http:
    +            response = http.request(
    +                "POST",
    +                f"{self.base_url}/redirect",
    +                fields={
    +                    "target": f"{self.base_url}/headers_and_params",
    +                    "status": "303 See Other",
    +                },
    +            )
    +        data = response.json()
    +        assert data["params"] == {}
    +        assert "Content-Type" not in HTTPHeaderDict(data["headers"])
    +
         def test_unknown_scheme(self) -> None:
             with PoolManager() as http:
                 unknown_scheme = "unknown"
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

17

News mentions

0

No linked articles in our index yet.