From 2fd4fea67857fa8d7809d89b0751176f60acd7c3 Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Thu, 18 Sep 2025 10:45:33 +0800 Subject: [PATCH] Fix CVE-2025-57833 --- CVE-2025-57833.patch | 74 ++++++++++++++++++++++++++++++++++++++++++++ python-django.spec | 6 +++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 CVE-2025-57833.patch diff --git a/CVE-2025-57833.patch b/CVE-2025-57833.patch new file mode 100644 index 0000000..5743ba4 --- /dev/null +++ b/CVE-2025-57833.patch @@ -0,0 +1,74 @@ +From: Jake Howard +Date: Wed, 13 Aug 2025 14:13:42 +0200 +Subject: [PATCH] [4.2.x] Fixed CVE-2025-57833 -- Protected FilteredRelation + against SQL injection in column aliases. + +Thanks Eyal Gabay (EyalSec) for the report. + +Backport of 51711717098d3f469f795dfa6bc3758b24f69ef7 from main. + +Origin: https://github.com/django/django/commit/31334e6965ad136a5e369993b01721499c5d1a92 +--- + django/db/models/sql/query.py | 1 + + tests/annotations/tests.py | 25 ++++++++++++++++++++++++- + 2 files changed, 25 insertions(+), 1 deletion(-) + +diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py +index 1e823cfe74b1..48852532f13f 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/tests/annotations/tests.py b/tests/annotations/tests.py +index 27cd7ebfb826..14d8d2ca9384 100644 +--- a/tests/annotations/tests.py ++++ b/tests/annotations/tests.py +@@ -3,7 +3,7 @@ from decimal import Decimal + + from django.core.exceptions import FieldDoesNotExist, FieldError + from django.db.models import ( +- BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func, ++ BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, FilteredRelation, Func, + IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value, + ) + from django.db.models.expressions import RawSQL +@@ -608,6 +608,24 @@ 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.alias(**{crafted_alias: FilteredRelation("authors")}) ++ ++ 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 +650,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")} ++ ) diff --git a/python-django.spec b/python-django.spec index e2788cf..2c886ae 100644 --- a/python-django.spec +++ b/python-django.spec @@ -1,7 +1,7 @@ %global _empty_manifest_terminate_build 0 Name: python-django Version: 2.2.27 -Release: 17 +Release: 18 Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design. License: Apache-2.0 and Python-2.0 and OFL-1.1 and MIT URL: https://www.djangoproject.com/ @@ -41,6 +41,7 @@ Patch22: CVE-2024-56374.patch Patch23: CVE-2025-26699.patch Patch24: CVE-2025-32873.patch Patch25: CVE-2025-48432.patch +Patch26: CVE-2025-57833.patch BuildArch: noarch %description @@ -107,6 +108,9 @@ mv %{buildroot}/doclist.lst . %{_docdir}/* %changelog +* Thu Sep 18 2025 yaoxin <1024769339@qq.com> - 2.2.27-18 +- Fix CVE-2025-57833 + * Mon Jun 09 2025 yaoxin <1024769339@qq.com> - 2.2.27-17 - Fix CVE-2025-48432 -- Gitee