summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJake Howard <git@theorangeone.net>2026-01-14 15:25:45 +0000
committerJacob Walls <jacobtylerwalls@gmail.com>2026-02-03 08:24:42 -0500
commitf578acc8c54530fffabd52d2db654c8669b011af (patch)
treecefccf69ba78097e45739c0a4fd61d8d05207451 /django
parent6dc23508f3395e1254c315084c7334ef81c4c09a (diff)
[4.2.x] Fixed CVE-2025-14550 -- Optimized repeated header parsing in ASGI requests.
Thanks Jiyong Yang for the report, and Natalia Bidart, Jacob Walls, and Shai Berger for reviews. Backport of eb22e1d6d643360e952609ef562c139a100ea4eb from main.
Diffstat (limited to 'django')
-rw-r--r--django/core/handlers/asgi.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/core/handlers/asgi.py b/django/core/handlers/asgi.py
index f0125e7321..d951823118 100644
--- a/django/core/handlers/asgi.py
+++ b/django/core/handlers/asgi.py
@@ -2,6 +2,7 @@ import logging
import sys
import tempfile
import traceback
+from collections import defaultdict
from asgiref.sync import ThreadSensitiveContext, sync_to_async
@@ -81,6 +82,7 @@ class ASGIRequest(HttpRequest):
self.META["SERVER_NAME"] = "unknown"
self.META["SERVER_PORT"] = "0"
# Headers go into META.
+ _headers = defaultdict(list)
for name, value in self.scope.get("headers", []):
name = name.decode("latin1")
if name == "content-length":
@@ -92,9 +94,8 @@ class ASGIRequest(HttpRequest):
# HTTP/2 say only ASCII chars are allowed in headers, but decode
# latin1 just in case.
value = value.decode("latin1")
- if corrected_name in self.META:
- value = self.META[corrected_name] + "," + value
- self.META[corrected_name] = value
+ _headers[corrected_name].append(value)
+ self.META.update({name: ",".join(value) for name, value in _headers.items()})
# Pull out request encoding, if provided.
self._set_content_type_params(self.META)
# Directly assign the body file to be our stream.