Skip to content

Commit 15ec5f9

Browse files
tech-sushantclaude
andcommitted
security: force Accept-Encoding identity to mitigate urllib3 decompression bomb (CTO-4807)
GHSA-mf9v-mfxr-j63j flags a decompression-bomb safeguard bypass in urllib3 < 2.7.0's streaming API. urllib3 2.7.0 requires Python >= 3.10 but the CI matrix still includes Python 3.9, so we cannot bump the pin. This patch installs a small monkey-patch on requests.adapters.HTTPAdapter that sets `Accept-Encoding: identity` on every outbound HTTP request. With no compressed responses ever arriving, urllib3's decompression code path is never exercised at runtime and the bug cannot trigger. - New module: EnigmaAutomation/security_mitigations.py - Imported once from EnigmaAutomation/__init__.py so it loads in every process (Django web, manage.py CLI, celery workers, pytest with DJANGO_SETTINGS_MODULE set). Note: SCA scanners detect by version, not behavior, so CTO-4807 will still flag urllib3==2.6.3. Requesting a risk-acceptance from security with this mitigation as justification, pending the Python upgrade that unblocks urllib3 2.7.0. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e4dc144 commit 15ec5f9

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

EnigmaAutomation/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from . import security_mitigations # noqa: F401 applied at import time
12
from .celery import app as celery_app
23

34
__all__ = ("celery_app",)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Runtime security mitigations applied at process startup.
3+
4+
Each mitigation here should reference the ticket / advisory it addresses
5+
and be removed once the underlying issue is properly resolved (typically
6+
by a dependency upgrade).
7+
"""
8+
9+
import requests.adapters
10+
11+
12+
_original_send = requests.adapters.HTTPAdapter.send
13+
14+
15+
def _force_identity_encoding(self, request, *args, **kwargs):
16+
"""Mitigation for GHSA-mf9v-mfxr-j63j (CTO-4807).
17+
18+
urllib3 < 2.7.0 has a decompression-bomb safeguard bypass in parts of
19+
its streaming API. urllib3 2.7.0 (the patched version) requires
20+
Python >= 3.10, but this project's CI matrix still includes Python 3.9
21+
so we cannot bump the pin.
22+
23+
Forcing Accept-Encoding: identity on every outbound HTTP request makes
24+
servers return uncompressed bodies, so urllib3's decompression code
25+
path is never exercised at runtime and the bug cannot trigger.
26+
27+
Remove this patch (and the import from EnigmaAutomation/__init__.py)
28+
once the Python runtime is upgraded and urllib3 can be bumped to
29+
>= 2.7.0.
30+
"""
31+
request.headers["Accept-Encoding"] = "identity"
32+
return _original_send(self, request, *args, **kwargs)
33+
34+
35+
requests.adapters.HTTPAdapter.send = _force_identity_encoding

0 commit comments

Comments
 (0)