Open redirect vulnerability in aiohttp
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.
| Package | Affected versions | Patched versions |
|---|---|---|
aiohttpPyPI | < 3.7.4 | 3.7.4 |
Affected products
1Patches
12545222a3853Merge branch 'ghsa-v6wp-4m6f-gcjg' into master
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- github.com/advisories/GHSA-v6wp-4m6f-gcjgghsaADVISORY
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/FU7ENI54JNEK3PHEFGCE46DGMFNTVU6L/mitrevendor-advisoryx_refsource_FEDORA
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/JN3V7CZJRT4QFCVXB6LDPCJH7NAOFCA5/mitrevendor-advisoryx_refsource_FEDORA
- nvd.nist.gov/vuln/detail/CVE-2021-21330ghsaADVISORY
- security.gentoo.org/glsa/202208-19ghsavendor-advisoryx_refsource_GENTOOWEB
- www.debian.org/security/2021/dsa-4864ghsavendor-advisoryx_refsource_DEBIANWEB
- github.com/aio-libs/aiohttp/blob/master/CHANGES.rstghsax_refsource_MISCWEB
- github.com/aio-libs/aiohttp/commit/2545222a3853e31ace15d87ae0e2effb7da0c96bghsax_refsource_MISCWEB
- github.com/aio-libs/aiohttp/security/advisories/GHSA-v6wp-4m6f-gcjgghsax_refsource_CONFIRMWEB
- github.com/pypa/advisory-database/tree/main/vulns/aiohttp/PYSEC-2021-76.yamlghsaWEB
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/FU7ENI54JNEK3PHEFGCE46DGMFNTVU6LghsaWEB
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/JN3V7CZJRT4QFCVXB6LDPCJH7NAOFCA5ghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/FU7ENI54JNEK3PHEFGCE46DGMFNTVU6LghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/JN3V7CZJRT4QFCVXB6LDPCJH7NAOFCA5ghsaWEB
- pypi.org/project/aiohttpghsaWEB
- pypi.org/project/aiohttp/mitrex_refsource_MISC
News mentions
0No linked articles in our index yet.