summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-09-24 15:56:03 -0400
committerNatalia <124304+nessita@users.noreply.github.com>2025-11-05 09:33:29 -0300
commitac9fcf6eb2c909f4150c5287808f49170ce1f9e2 (patch)
treeb24529bb3f7efe221a4edfc35913e89d7fdf4d1b /django
parent6703f364d767e949c5b0e4016433ef75063b4f9b (diff)
[5.2.x] Refs CVE-2025-64459 -- Avoided propagating invalid arguments to Q on dictionary expansion.
Backport of 3c3f46357718166069948625354b8315a8505262 from main.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 535d91d767..8ed028d140 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -42,6 +42,8 @@ MAX_GET_RESULTS = 21
# The maximum number of items to display in a QuerySet.__repr__
REPR_OUTPUT_SIZE = 20
+PROHIBITED_FILTER_KWARGS = frozenset(["_connector", "_negated"])
+
class BaseIterable:
def __init__(
@@ -1512,6 +1514,9 @@ class QuerySet(AltersData):
return clone
def _filter_or_exclude_inplace(self, negate, args, kwargs):
+ if invalid_kwargs := PROHIBITED_FILTER_KWARGS.intersection(kwargs):
+ invalid_kwargs_str = ", ".join(f"'{k}'" for k in sorted(invalid_kwargs))
+ raise TypeError(f"The following kwargs are invalid: {invalid_kwargs_str}")
if negate:
self._query.add_q(~Q(*args, **kwargs))
else: