From a45d8b0e1e3b090b9b73f0cc36f29ec9f7d11d87 Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Thu, 4 Sep 2025 09:34:58 +0800 Subject: [PATCH] Fix CVE-2025-57833 --- CVE-2025-57833.patch | 84 ++++++++++++++++++++++++++++++++++++++++++++ python-django.spec | 6 +++- 2 files changed, 89 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..bc228fe --- /dev/null +++ b/CVE-2025-57833.patch @@ -0,0 +1,84 @@ +From 4c044fcc866ec226f612c475950b690b0139d243 Mon Sep 17 00:00:00 2001 +From: Jake Howard +Date: Wed, 13 Aug 2025 14:13:42 +0200 +Subject: [PATCH] [5.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/4c044fcc866ec226f612c475950b690b0139d243 +--- + django/db/models/sql/query.py | 1 + + tests/annotations/tests.py | 24 ++++++++++++++++++++++++ + 2 files changed, 25 insertions(+) + +diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py +index 92a09c5..a75d9e8 100644 +--- a/django/db/models/sql/query.py ++++ b/django/db/models/sql/query.py +@@ -1696,6 +1696,7 @@ class Query(BaseExpression): + return target_clause, needed_inner + + def add_filtered_relation(self, filtered_relation, alias): ++ self.check_alias(alias) + filtered_relation.alias = alias + relation_lookup_parts, relation_field_parts, _ = self.solve_lookup_type( + filtered_relation.relation_name +diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py +index 6c0d7b6..060d632 100644 +--- a/tests/annotations/tests.py ++++ b/tests/annotations/tests.py +@@ -14,6 +14,7 @@ from django.db.models import ( + Exists, + ExpressionWrapper, + F, ++ FilteredRelation, + FloatField, + Func, + IntegerField, +@@ -1164,6 +1165,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', +@@ -1189,6 +1199,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")} ++ ) ++ + @skipUnless(connection.vendor == "postgresql", "PostgreSQL tests") + @skipUnlessDBFeature("supports_json_field") + def test_set_returning_functions(self): +@@ -1482,3 +1497,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.50.1 + diff --git a/python-django.spec b/python-django.spec index 7be51f7..81588f5 100644 --- a/python-django.spec +++ b/python-django.spec @@ -1,11 +1,12 @@ %global _empty_manifest_terminate_build 0 Name: python-django Version: 5.2.5 -Release: 1 +Release: 2 Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design. License: Apache-2.0 and Python-2.0 and BSD-3-Clause URL: https://www.djangoproject.com/ Source0: https://files.pythonhosted.org/packages/source/d/django/django-%{version}.tar.gz +Patch0: CVE-2025-57833.patch BuildArch: noarch %description @@ -74,6 +75,9 @@ mv %{buildroot}/doclist.lst . %{_pkgdocdir}/* %changelog +* Thu Sep 04 2025 yaoxin <1024769339@qq.com> - 5.2.5-2 +- Fix CVE-2025-57833 + * Wed Aug 20 2025 zhang_wenyu - 5.2.5-1 - update python-django to 5.2.5 * Fixed a regression in Django 5.2.1 that prevented the usage of ``UNNEST`` PostgreSQL strategy of ``QuerySet.bulk_create()`` with foreign keys -- Gitee