VYPR
Low severityNVD Advisory· Published Feb 26, 2021· Updated Aug 3, 2024

Open redirect vulnerability in aiohttp

CVE-2021-21330

Description

aiohttp is an asynchronous HTTP client/server framework for asyncio and Python. In aiohttp before version 3.7.4 there is an open redirect vulnerability. A maliciously crafted link to an aiohttp-based web-server could redirect the browser to a different website. It is caused by a bug in the aiohttp.web_middlewares.normalize_path_middleware middleware. This security problem has been fixed in 3.7.4. Upgrade your dependency using pip as follows "pip install aiohttp >= 3.7.4". If upgrading is not an option for you, a workaround can be to avoid using aiohttp.web_middlewares.normalize_path_middleware in your applications.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
aiohttpPyPI
< 3.7.43.7.4

Affected products

1

Patches

1
2545222a3853

Merge branch 'ghsa-v6wp-4m6f-gcjg' into master

https://github.com/aio-libs/aiohttpSviatoslav SydorenkoFeb 25, 2021via ghsa
3 files changed · +42 0
  • aiohttp/web_middlewares.py+1 0 modified
    @@ -108,6 +108,7 @@ async def impl(request: Request, handler: _Handler) -> StreamResponse:
                     paths_to_check.append(merged_slashes[:-1])
     
                 for path in paths_to_check:
    +                path = re.sub("^//+", "/", path)  # SECURITY: GHSA-v6wp-4m6f-gcjg
                     resolves, request = await _check_request_resolves(request, path)
                     if resolves:
                         raise redirect_class(request.raw_path + query)
    
  • CHANGES/5497.bugfix+9 0 added
    @@ -0,0 +1,9 @@
    +**(SECURITY BUG)** Started preventing open redirects in the
    +``aiohttp.web.normalize_path_middleware`` middleware. For
    +more details, see
    +https://github.com/aio-libs/aiohttp/security/advisories/GHSA-v6wp-4m6f-gcjg.
    +
    +Thanks to `Beast Glatisant <https://github.com/g147>`__ for
    +finding the firstinstance of this issue and `Jelmer Vernooij
    +<https://jelmer.uk/>`__ for reporting and tracking it down
    +in aiohttp.
    
  • tests/test_web_middleware.py+32 0 modified
    @@ -361,6 +361,38 @@ async def test_cannot_remove_and_add_slash(self) -> None:
             with pytest.raises(AssertionError):
                 web.normalize_path_middleware(append_slash=True, remove_slash=True)
     
    +    @pytest.mark.parametrize(
    +        ["append_slash", "remove_slash"],
    +        [
    +            (True, False),
    +            (False, True),
    +            (False, False),
    +        ],
    +    )
    +    async def test_open_redirects(
    +        self, append_slash: bool, remove_slash: bool, aiohttp_client: Any
    +    ) -> None:
    +        async def handle(request: web.Request) -> web.StreamResponse:
    +            pytest.fail(
    +                msg="Security advisory 'GHSA-v6wp-4m6f-gcjg' test handler "
    +                "matched unexpectedly",
    +                pytrace=False,
    +            )
    +
    +        app = web.Application(
    +            middlewares=[
    +                web.normalize_path_middleware(
    +                    append_slash=append_slash, remove_slash=remove_slash
    +                )
    +            ]
    +        )
    +        app.add_routes([web.get("/", handle), web.get("/google.com", handle)])
    +        client = await aiohttp_client(app, server_kwargs={"skip_url_asserts": True})
    +        resp = await client.get("//google.com", allow_redirects=False)
    +        assert resp.status == 308
    +        assert resp.headers["Location"] == "/google.com"
    +        assert resp.url.query == URL("//google.com").query
    +
     
     async def test_bug_3669(aiohttp_client: Any):
         async def paymethod(request):
    

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

16

News mentions

0

No linked articles in our index yet.