mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed CVE-2025-64459 -- Prevented SQL injections in Q/QuerySet via the _connector kwarg.
Thanks cyberstan for the report, Sarah Boyce, Adam Johnson, Simon Charette, and Jake Howard for the reviews.
This commit is contained in:
@@ -48,8 +48,12 @@ class Q(tree.Node):
|
|||||||
XOR = "XOR"
|
XOR = "XOR"
|
||||||
default = AND
|
default = AND
|
||||||
conditional = True
|
conditional = True
|
||||||
|
connectors = (None, AND, OR, XOR)
|
||||||
|
|
||||||
def __init__(self, *args, _connector=None, _negated=False, **kwargs):
|
def __init__(self, *args, _connector=None, _negated=False, **kwargs):
|
||||||
|
if _connector not in self.connectors:
|
||||||
|
connector_reprs = ", ".join(f"{conn!r}" for conn in self.connectors[1:])
|
||||||
|
raise ValueError(f"_connector must be one of {connector_reprs}, or None.")
|
||||||
super().__init__(
|
super().__init__(
|
||||||
children=[*args, *sorted(kwargs.items())],
|
children=[*args, *sorted(kwargs.items())],
|
||||||
connector=_connector,
|
connector=_connector,
|
||||||
|
|||||||
@@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
|
|||||||
:func:`redirect() <django.shortcuts.redirect>` were subject to a potential
|
:func:`redirect() <django.shortcuts.redirect>` were subject to a potential
|
||||||
denial-of-service attack via certain inputs with a very large number of Unicode
|
denial-of-service attack via certain inputs with a very large number of Unicode
|
||||||
characters (follow up to :cve:`2025-27556`).
|
characters (follow up to :cve:`2025-27556`).
|
||||||
|
|
||||||
|
CVE-2025-64459: Potential SQL injection via ``_connector`` keyword argument
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
:meth:`.QuerySet.filter`, :meth:`~.QuerySet.exclude`, :meth:`~.QuerySet.get`,
|
||||||
|
and :class:`~.Q` were subject to SQL injection using a suitably crafted
|
||||||
|
dictionary, with dictionary expansion, as the ``_connector`` argument.
|
||||||
|
|||||||
@@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
|
|||||||
:func:`redirect() <django.shortcuts.redirect>` were subject to a potential
|
:func:`redirect() <django.shortcuts.redirect>` were subject to a potential
|
||||||
denial-of-service attack via certain inputs with a very large number of Unicode
|
denial-of-service attack via certain inputs with a very large number of Unicode
|
||||||
characters (follow up to :cve:`2025-27556`).
|
characters (follow up to :cve:`2025-27556`).
|
||||||
|
|
||||||
|
CVE-2025-64459: Potential SQL injection via ``_connector`` keyword argument
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
:meth:`.QuerySet.filter`, :meth:`~.QuerySet.exclude`, :meth:`~.QuerySet.get`,
|
||||||
|
and :class:`~.Q` were subject to SQL injection using a suitably crafted
|
||||||
|
dictionary, with dictionary expansion, as the ``_connector`` argument.
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
|
|||||||
denial-of-service attack via certain inputs with a very large number of Unicode
|
denial-of-service attack via certain inputs with a very large number of Unicode
|
||||||
characters (follow up to :cve:`2025-27556`).
|
characters (follow up to :cve:`2025-27556`).
|
||||||
|
|
||||||
|
CVE-2025-64459: Potential SQL injection via ``_connector`` keyword argument
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
|
:meth:`.QuerySet.filter`, :meth:`~.QuerySet.exclude`, :meth:`~.QuerySet.get`,
|
||||||
|
and :class:`~.Q` were subject to SQL injection using a suitably crafted
|
||||||
|
dictionary, with dictionary expansion, as the ``_connector`` argument.
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
|
|||||||
@@ -272,6 +272,11 @@ class QTests(SimpleTestCase):
|
|||||||
Q(*items, _connector=connector),
|
Q(*items, _connector=connector),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_connector_validation(self):
|
||||||
|
msg = f"_connector must be one of {Q.AND!r}, {Q.OR!r}, {Q.XOR!r}, or None."
|
||||||
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
|
Q(_connector="evil")
|
||||||
|
|
||||||
def test_referenced_base_fields(self):
|
def test_referenced_base_fields(self):
|
||||||
# Make sure Q.referenced_base_fields retrieves all base fields from
|
# Make sure Q.referenced_base_fields retrieves all base fields from
|
||||||
# both filters and F expressions.
|
# both filters and F expressions.
|
||||||
|
|||||||
Reference in New Issue
Block a user