VYPR
Critical severityNVD Advisory· Published Nov 5, 2025· Updated Feb 26, 2026

Potential SQL injection via _connector keyword argument in QuerySet and Q objects

CVE-2025-64459

Description

An issue was discovered in 5.1 before 5.1.14, 4.2 before 4.2.26, and 5.2 before 5.2.8. The methods QuerySet.filter(), QuerySet.exclude(), and QuerySet.get(), and the class Q(), are subject to SQL injection when using a suitably crafted dictionary, with dictionary expansion, as the _connector argument. Earlier, unsupported Django series (such as 5.0.x, 4.1.x, and 3.2.x) were not evaluated and may also be affected. Django would like to thank cyberstan for reporting this issue.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
djangoPyPI
>= 5.2a1, < 5.2.85.2.8
djangoPyPI
>= 5.0a1, < 5.1.145.1.14
djangoPyPI
< 4.2.264.2.26

Affected products

1

Patches

4
72d2c87431f2

[5.1.x] Fixed CVE-2025-64459 -- Prevented SQL injections in Q/QuerySet via the _connector kwarg.

https://github.com/django/djangoJacob WallsSep 24, 2025via ghsa
4 files changed · +23 0
  • django/db/models/query_utils.py+4 0 modified
    @@ -47,8 +47,12 @@ class Q(tree.Node):
         XOR = "XOR"
         default = AND
         conditional = True
    +    connectors = (None, AND, OR, XOR)
     
         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__(
                 children=[*args, *sorted(kwargs.items())],
                 connector=_connector,
    
  • docs/releases/4.2.26.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • docs/releases/5.1.14.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • tests/queries/test_q.py+5 0 modified
    @@ -264,6 +264,11 @@ def test_create_helper(self):
                         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):
             # Make sure Q.referenced_base_fields retrieves all base fields from
             # both filters and F expressions.
    
59ae82e67053

[4.2.x] Fixed CVE-2025-64459 -- Prevented SQL injections in Q/QuerySet via the _connector kwarg.

https://github.com/django/djangoJacob WallsSep 24, 2025via ghsa
3 files changed · +16 0
  • django/db/models/query_utils.py+4 0 modified
    @@ -44,8 +44,12 @@ class Q(tree.Node):
         XOR = "XOR"
         default = AND
         conditional = True
    +    connectors = (None, AND, OR, XOR)
     
         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__(
                 children=[*args, *sorted(kwargs.items())],
                 connector=_connector,
    
  • docs/releases/4.2.26.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • tests/queries/test_q.py+5 0 modified
    @@ -225,6 +225,11 @@ def test_create_helper(self):
                         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")
    +
     
     class QCheckTests(TestCase):
         def test_basic(self):
    
06dd38324ac3

[6.0.x] Fixed CVE-2025-64459 -- Prevented SQL injections in Q/QuerySet via the _connector kwarg.

https://github.com/django/djangoJacob WallsSep 24, 2025via ghsa
5 files changed · +30 0
  • django/db/models/query_utils.py+4 0 modified
    @@ -48,8 +48,12 @@ class Q(tree.Node):
         XOR = "XOR"
         default = AND
         conditional = True
    +    connectors = (None, AND, OR, XOR)
     
         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__(
                 children=[*args, *sorted(kwargs.items())],
                 connector=_connector,
    
  • docs/releases/4.2.26.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • docs/releases/5.1.14.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • docs/releases/5.2.8.txt+7 0 modified
    @@ -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
     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
     ========
     
    
  • tests/queries/test_q.py+5 0 modified
    @@ -272,6 +272,11 @@ def test_create_helper(self):
                         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):
             # Make sure Q.referenced_base_fields retrieves all base fields from
             # both filters and F expressions.
    
6703f364d767

[5.2.x] Fixed CVE-2025-64459 -- Prevented SQL injections in Q/QuerySet via the _connector kwarg.

https://github.com/django/djangoJacob WallsSep 24, 2025via ghsa
5 files changed · +30 0
  • django/db/models/query_utils.py+4 0 modified
    @@ -48,8 +48,12 @@ class Q(tree.Node):
         XOR = "XOR"
         default = AND
         conditional = True
    +    connectors = (None, AND, OR, XOR)
     
         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__(
                 children=[*args, *sorted(kwargs.items())],
                 connector=_connector,
    
  • docs/releases/4.2.26.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • docs/releases/5.1.14.txt+7 0 modified
    @@ -16,3 +16,10 @@ Windows. As a consequence, :class:`~django.http.HttpResponseRedirect`,
     :func:`redirect() <django.shortcuts.redirect>` were subject to a potential
     denial-of-service attack via certain inputs with a very large number of Unicode
     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.
    
  • docs/releases/5.2.8.txt+7 0 modified
    @@ -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
     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
     ========
     
    
  • tests/queries/test_q.py+5 0 modified
    @@ -272,6 +272,11 @@ def test_create_helper(self):
                         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):
             # Make sure Q.referenced_base_fields retrieves all base fields from
             # both filters and F expressions.
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

12

News mentions

0

No linked articles in our index yet.