GHSA-5vjj-2r48-q622: Pip/zapros vulnerability
Impact
Who is impacted: - Any application using Zapros to make HTTP requests to untrusted servers - Applications that follow redirects to attacker-controlled hosts
Attack vector: - A malicious HTTP server returns a response with many chained content encodings. When the client attempts to decode, it creates a deeply nested decompression chain consuming excessive resources.
Patches
Fixed in version 0.14.0.
The fix adds a hardcoded limit of 5 Content-Encoding layers. Responses exceeding this limit raise DecodingError.
Workarounds
Add middleware that checks for a malicious Content-Encoding header.
python from typing import cast
from zapros import ( AsyncBaseHandler, AsyncBaseMiddleware, BaseHandler, BaseMiddleware, Client, DecodingError, Request, Response, )
MAXDECODELAYERS = 5
class ContentEncodingCheckMiddleware(BaseMiddleware, AsyncBaseMiddleware): def init( self, nexthandler: BaseHandler | AsyncBaseHandler, , maxlayers: int = MAXDECODELAYERS, ) -> None: self.next = cast(BaseHandler, nexthandler) self.asyncnext = cast(AsyncBaseHandler, nexthandler) self.maxlayers = maxlayers
def check(self, response: Response) -> None: encodingheader = response.headers.get("Content-Encoding") if not encodingheader: return
layers = [enc.strip().lower() for enc in encodingheader.split(",") if enc.strip()] if len(layers) > self.maxlayers: raise DecodingError(f"Too many Content-Encoding layers ({len(layers)}), maximum is {self.maxlayers}")
def handle(self, request: Request) -> Response: response = self.next.handle(request) self.check(response) return response
async def ahandle(self, request: Request) -> Response: response = await self.asyncnext.ahandle(request) self.check(response) return response
with Client().wrapwithmiddleware(lambda next: ContentEncodingCheckMiddleware(next)) as client: ...
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/zaprosto a version that resolves this vulnerability.Fixed in 0.14.0 - Upgrade
Upgrade
Zaprosto a version that resolves this vulnerability.Fixed in 0.14.0 - Compensating control
Add ContentEncodingCheckMiddleware to HTTP clients to inspect the Content-Encoding response header and reject responses with more than 5 encoding layers by raising DecodingError.
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Applications using Zapros to make HTTP requests to untrusted servers are impacted. Applications that follow redirects to attacker-controlled hosts are also exposed.
What must an attacker do to trigger the resource exhaustion?
An attacker needs to operate or control a server that returns an HTTP response with many chained Content-Encoding values. When Zapros decodes that response, the deeply nested decompression chain can consume excessive resources.
What version contains the fix, and how does it behave?
Zapros 0.14.0 fixes the issue by enforcing a hardcoded maximum of five Content-Encoding layers. A response exceeding that limit raises DecodingError.
What can be done if upgrading is not immediately possible?
Add middleware that inspects the Content-Encoding header and rejects responses with more than five encoding layers. The provided workaround uses a maximum of five layers to match the patched behavior.