new file mode 100644
@@ -0,0 +1,96 @@
+From 31334e6965ad136a5e369993b01721499c5d1a92 Mon Sep 17 00:00:00 2001
+From: Jake Howard <git@theorangeone.net>
+Date: Wed, 13 Aug 2025 14:13:42 +0200
+Subject: [PATCH] Fixed CVE-2025-57833 -- Protected FilteredRelation against
+ SQL injection in column aliases.
+
+Thanks Eyal Gabay (EyalSec) for the report.
+
+Backport of 51711717098d3f469f795dfa6bc3758b24f69ef7 from main.
+
+CVE: CVE-2025-57833
+
+Upstream-Status: Backport
+https://github.com/django/django/commit/31334e6965ad136a5e369993b01721499c5d1a92
+
+Signed-off-by: Jake Howard <git@theorangeone.net>
+Signed-off-by: Saravanan <saravanan.kadambathursubramaniyam@windriver.com>
+---
+ django/db/models/sql/query.py | 1 +
+ docs/releases/2.2.28.txt | 7 +++++++
+ tests/annotations/tests.py | 18 ++++++++++++++++--
+ 3 files changed, 24 insertions(+), 2 deletions(-)
+
+diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
+index 9b054bd..96a6f5f 100644
+--- a/django/db/models/sql/query.py
++++ b/django/db/models/sql/query.py
+@@ -1369,6 +1369,7 @@ class Query:
+ return target_clause
+
+ def add_filtered_relation(self, filtered_relation, alias):
++ self.check_alias(alias)
+ filtered_relation.alias = alias
+ lookups = dict(get_children_from_q(filtered_relation.condition))
+ for lookup in chain((filtered_relation.relation_name,), lookups):
+diff --git a/docs/releases/2.2.28.txt b/docs/releases/2.2.28.txt
+index 9853d95..1a824c1 100644
+--- a/docs/releases/2.2.28.txt
++++ b/docs/releases/2.2.28.txt
+@@ -6,6 +6,13 @@ Django 2.2.28 release notes
+
+ Django 2.2.28 fixes two security issues with severity "high" in 2.2.27.
+
++CVE-2025-57833: Potential SQL injection in ``FilteredRelation`` column aliases
++==============================================================================
++
++:class:`.FilteredRelation` was subject to SQL injection in column aliases,
++using a suitably crafted dictionary, with dictionary expansion, as the
++``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias`.
++
+ CVE-2024-56374: Potential denial-of-service vulnerability in IPv6 validation
+ ============================================================================
+
+diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
+index 27cd7eb..cdffb07 100644
+--- a/tests/annotations/tests.py
++++ b/tests/annotations/tests.py
+@@ -3,8 +3,8 @@ from decimal import Decimal
+
+ from django.core.exceptions import FieldDoesNotExist, FieldError
+ from django.db.models import (
+- BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
+- IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value,
++ BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, FilteredRelation,
++ Func, IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value,
+ )
+ from django.db.models.expressions import RawSQL
+ from django.db.models.functions import Length, Lower
+@@ -608,6 +608,15 @@ class NonAggregateAnnotationTestCase(TestCase):
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.annotate(**{crafted_alias: Value(1)})
+
++ def test_alias_filtered_relation_sql_injection(self):
++ crafted_alias = """injected_name" from "annotations_book"; --"""
++ msg = (
++ "Column aliases cannot contain whitespace characters, quotation marks, "
++ "semicolons, or SQL comments."
++ )
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.annotate(**{crafted_alias: FilteredRelation("author")})
++
+ def test_alias_forbidden_chars(self):
+ tests = [
+ 'al"ias',
+@@ -632,3 +641,8 @@ class NonAggregateAnnotationTestCase(TestCase):
+ with self.subTest(crafted_alias):
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.annotate(**{crafted_alias: Value(1)})
++
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.annotate(
++ **{crafted_alias: FilteredRelation("authors")}
++ )
+--
+2.35.5
+
new file mode 100644
@@ -0,0 +1,107 @@
+From 9c8cc0c011772179c21d62b17aadee5c3ee3c2aa Mon Sep 17 00:00:00 2001
+From: Jake Howard <git@theorangeone.net>
+Date: Wed, 13 Aug 2025 14:13:42 +0200
+Subject: [PATCH] Fixed CVE-2025-57833 -- Protected FilteredRelation against
+ SQL injection in column aliases.
+
+Thanks Eyal Gabay (EyalSec) for the report.
+
+Backport of 51711717098d3f469f795dfa6bc3758b24f69ef7 from main.
+
+CVE: CVE-2025-57833
+
+Upstream-Status: Backport
+https://github.com/django/django/commit/31334e6965ad136a5e369993b01721499c5d1a92
+
+Signed-off-by: Jake Howard <git@theorangeone.net>
+Signed-off-by: Saravanan <saravanan.kadambathursubramaniyam@windriver.com>
+---
+ django/db/models/sql/query.py | 1 +
+ docs/releases/3.2.23.txt | 7 +++++++
+ tests/annotations/tests.py | 25 ++++++++++++++++++++++++-
+ 3 files changed, 32 insertions(+), 1 deletion(-)
+
+diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
+index 230b6fa..e56ff81 100644
+--- a/django/db/models/sql/query.py
++++ b/django/db/models/sql/query.py
+@@ -1466,6 +1466,7 @@ class Query(BaseExpression):
+ return target_clause
+
+ def add_filtered_relation(self, filtered_relation, alias):
++ self.check_alias(alias)
+ filtered_relation.alias = alias
+ lookups = dict(get_children_from_q(filtered_relation.condition))
+ relation_lookup_parts, relation_field_parts, _ = self.solve_lookup_type(filtered_relation.relation_name)
+diff --git a/docs/releases/3.2.23.txt b/docs/releases/3.2.23.txt
+index 9a9b52d..329aed1 100644
+--- a/docs/releases/3.2.23.txt
++++ b/docs/releases/3.2.23.txt
+@@ -45,3 +45,10 @@ which has now been updated to define a ``max_length`` of 39 characters.
+ The :class:`django.db.models.GenericIPAddressField` model field was not
+ affected.
+
++CVE-2025-57833: Potential SQL injection in ``FilteredRelation`` column aliases
++==============================================================================
++
++:class:`.FilteredRelation` was subject to SQL injection in column aliases,
++using a suitably crafted dictionary, with dictionary expansion, as the
++``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias`.
++
+diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
+index 8082c7a..00d4ee6 100644
+--- a/tests/annotations/tests.py
++++ b/tests/annotations/tests.py
+@@ -4,7 +4,7 @@ from decimal import Decimal
+ from django.core.exceptions import FieldDoesNotExist, FieldError
+ from django.db.models import (
+ BooleanField, Case, CharField, Count, DateTimeField, DecimalField, Exists,
+- ExpressionWrapper, F, FloatField, Func, IntegerField, Max,
++ ExpressionWrapper, F, FilteredRelation, FloatField, Func, IntegerField, Max,
+ NullBooleanField, OuterRef, Q, Subquery, Sum, Value, When,
+ )
+ from django.db.models.expressions import RawSQL
+@@ -775,6 +775,15 @@ class NonAggregateAnnotationTestCase(TestCase):
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.annotate(**{crafted_alias: Value(1)})
+
++ def test_alias_filtered_relation_sql_injection(self):
++ crafted_alias = """injected_name" from "annotations_book"; --"""
++ msg = (
++ "Column aliases cannot contain whitespace characters, quotation marks, "
++ "semicolons, or SQL comments."
++ )
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.annotate(**{crafted_alias: FilteredRelation("author")})
++
+ def test_alias_forbidden_chars(self):
+ tests = [
+ 'al"ias',
+@@ -800,6 +809,11 @@ class NonAggregateAnnotationTestCase(TestCase):
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.annotate(**{crafted_alias: Value(1)})
+
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.annotate(
++ **{crafted_alias: FilteredRelation("authors")}
++ )
++
+
+ class AliasTests(TestCase):
+ @classmethod
+@@ -1039,3 +1053,12 @@ class AliasTests(TestCase):
+ )
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.alias(**{crafted_alias: Value(1)})
++
++ def test_alias_filtered_relation_sql_injection(self):
++ crafted_alias = """injected_name" from "annotations_book"; --"""
++ msg = (
++ "Column aliases cannot contain whitespace characters, quotation marks, "
++ "semicolons, or SQL comments."
++ )
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.alias(**{crafted_alias: FilteredRelation("authors")})
+--
+2.35.5
+
new file mode 100644
@@ -0,0 +1,106 @@
+From 31334e6965ad136a5e369993b01721499c5d1a92 Mon Sep 17 00:00:00 2001
+From: Jake Howard <git@theorangeone.net>
+Date: Wed, 13 Aug 2025 14:13:42 +0200
+Subject: [PATCH] Fixed CVE-2025-57833 -- Protected FilteredRelation against
+ SQL injection in column aliases.
+
+Thanks Eyal Gabay (EyalSec) for the report.
+
+Backport of 51711717098d3f469f795dfa6bc3758b24f69ef7 from main.
+
+CVE: CVE-2025-57833
+
+Upstream-Status: Backport
+https://github.com/django/django/commit/31334e6965ad136a5e369993b01721499c5d1a92
+
+Signed-off-by: Jake Howard <git@theorangeone.net>
+Signed-off-by: Saravanan <saravanan.kadambathursubramaniyam@windriver.com>
+---
+ django/db/models/sql/query.py | 1 +
+ docs/releases/4.2.17.txt | 7 +++++++
+ tests/annotations/tests.py | 24 ++++++++++++++++++++++++
+ 3 files changed, 32 insertions(+)
+
+diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
+index e68fd9e..5a1b685 100644
+--- a/django/db/models/sql/query.py
++++ b/django/db/models/sql/query.py
+@@ -1620,6 +1620,7 @@ class Query(BaseExpression):
+ return target_clause
+
+ def add_filtered_relation(self, filtered_relation, alias):
++ self.check_alias(alias)
+ filtered_relation.alias = alias
+ lookups = dict(get_children_from_q(filtered_relation.condition))
+ relation_lookup_parts, relation_field_parts, _ = self.solve_lookup_type(
+diff --git a/docs/releases/4.2.17.txt b/docs/releases/4.2.17.txt
+index 1392724..3a0815b 100644
+--- a/docs/releases/4.2.17.txt
++++ b/docs/releases/4.2.17.txt
+@@ -50,3 +50,10 @@ which has now been updated to define a ``max_length`` of 39 characters.
+
+ The :class:`django.db.models.GenericIPAddressField` model field was not
+ affected.
++
++CVE-2025-57833: Potential SQL injection in ``FilteredRelation`` column aliases
++==============================================================================
++
++:class:`.FilteredRelation` was subject to SQL injection in column aliases,
++using a suitably crafted dictionary, with dictionary expansion, as the
++``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias`.
+diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
+index e0cdbf1..a8474ab 100644
+--- a/tests/annotations/tests.py
++++ b/tests/annotations/tests.py
+@@ -12,6 +12,7 @@ from django.db.models import (
+ Exists,
+ ExpressionWrapper,
+ F,
++ FilteredRelation,
+ FloatField,
+ Func,
+ IntegerField,
+@@ -1121,6 +1122,15 @@ class NonAggregateAnnotationTestCase(TestCase):
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.annotate(**{crafted_alias: Value(1)})
+
++ def test_alias_filtered_relation_sql_injection(self):
++ crafted_alias = """injected_name" from "annotations_book"; --"""
++ msg = (
++ "Column aliases cannot contain whitespace characters, quotation marks, "
++ "semicolons, or SQL comments."
++ )
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.annotate(**{crafted_alias: FilteredRelation("author")})
++
+ def test_alias_forbidden_chars(self):
+ tests = [
+ 'al"ias',
+@@ -1146,6 +1156,11 @@ class NonAggregateAnnotationTestCase(TestCase):
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.annotate(**{crafted_alias: Value(1)})
+
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.annotate(
++ **{crafted_alias: FilteredRelation("authors")}
++ )
++
+
+ class AliasTests(TestCase):
+ @classmethod
+@@ -1418,3 +1433,12 @@ class AliasTests(TestCase):
+ )
+ with self.assertRaisesMessage(ValueError, msg):
+ Book.objects.alias(**{crafted_alias: Value(1)})
++
++ def test_alias_filtered_relation_sql_injection(self):
++ crafted_alias = """injected_name" from "annotations_book"; --"""
++ msg = (
++ "Column aliases cannot contain whitespace characters, quotation marks, "
++ "semicolons, or SQL comments."
++ )
++ with self.assertRaisesMessage(ValueError, msg):
++ Book.objects.alias(**{crafted_alias: FilteredRelation("authors")})
+--
+2.35.5
+
@@ -27,6 +27,7 @@ SRC_URI += "file://CVE-2023-31047.patch \
file://CVE-2024-27351.patch \
file://CVE-2025-26699.patch \
file://CVE-2024-56374.patch \
+ file://CVE-2025-57833.patch \
"
SRC_URI[sha256sum] = "0200b657afbf1bc08003845ddda053c7641b9b24951e52acd51f6abda33a7413"
@@ -10,6 +10,7 @@ SRC_URI += "\
file://CVE-2024-27351.patch \
file://CVE-2025-26699.patch \
file://CVE-2024-56374.patch \
+ file://CVE-2025-57833.patch \
"
# Set DEFAULT_PREFERENCE so that the LTS version of django is built by
@@ -10,6 +10,7 @@ RDEPENDS:${PN} += "\
SRC_URI += "\
file://CVE-2025-26699.patch \
file://CVE-2024-56374.patch \
+ file://CVE-2025-57833.patch \
"
# Set DEFAULT_PREFERENCE so that the LTS version of django is built by
Reference: https://nvd.nist.gov/vuln/detail/CVE-2025-57833 Upstream-patch: https://github.com/django/django/commit/31334e6965ad136a5e369993b01721499c5d1a92 Signed-off-by: Saravanan <saravanan.kadambathursubramaniyam@windriver.com> --- .../CVE-2025-57833.patch | 96 ++++++++++++++++ .../CVE-2025-57833.patch | 107 ++++++++++++++++++ .../CVE-2025-57833.patch | 106 +++++++++++++++++ .../python/python3-django_2.2.28.bb | 1 + .../python/python3-django_3.2.23.bb | 1 + .../python/python3-django_4.2.17.bb | 1 + 6 files changed, 312 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-django-2.2.28/CVE-2025-57833.patch create mode 100644 meta-python/recipes-devtools/python/python3-django-3.2.23/CVE-2025-57833.patch create mode 100644 meta-python/recipes-devtools/python/python3-django-4.2.17/CVE-2025-57833.patch