File tree Expand file tree Collapse file tree 5 files changed +45
–1
lines changed
django/db/backends/postgresql Expand file tree Collapse file tree 5 files changed +45
–1
lines changed Original file line number Diff line number Diff line change 11from django .db .models .sql .compiler import ( # isort:skip
22 SQLAggregateCompiler ,
3- SQLCompiler ,
3+ SQLCompiler as BaseSQLCompiler ,
44 SQLDeleteCompiler ,
55 SQLInsertCompiler as BaseSQLInsertCompiler ,
66 SQLUpdateCompiler ,
@@ -25,6 +25,15 @@ def __str__(self):
2525 return "UNNEST(%s)" % ", " .join (self )
2626
2727
28+ class SQLCompiler (BaseSQLCompiler ):
29+ def quote_name_unless_alias (self , name ):
30+ if "$" in name :
31+ raise ValueError (
32+ "Dollar signs are not permitted in column aliases on PostgreSQL."
33+ )
34+ return super ().quote_name_unless_alias (name )
35+
36+
2837class SQLInsertCompiler (BaseSQLInsertCompiler ):
2938 def assemble_as_sql (self , fields , value_rows ):
3039 # Specialize bulk-insertion of literal values through UNNEST to
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ Django 4.2.27 release notes
77Django 4.2.27 fixes one security issue with severity "high", one security issue
88with severity "moderate", and one bug in 4.2.26.
99
10+ CVE-2025-13372: Potential SQL injection in ``FilteredRelation`` column aliases on PostgreSQL
11+ ============================================================================================
12+
13+ :class:`.FilteredRelation` was subject to SQL injection in column aliases,
14+ using a suitably crafted dictionary, with dictionary expansion, as the
15+ ``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias` on
16+ PostgreSQL.
17+
1018Bugfixes
1119========
1220
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ Django 5.1.15 release notes
77Django 5.1.15 fixes one security issue with severity "high", one security issue
88with severity "moderate", and one bug in 5.1.14.
99
10+ CVE-2025-13372: Potential SQL injection in ``FilteredRelation`` column aliases on PostgreSQL
11+ ============================================================================================
12+
13+ :class:`.FilteredRelation` was subject to SQL injection in column aliases,
14+ using a suitably crafted dictionary, with dictionary expansion, as the
15+ ``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias` on
16+ PostgreSQL.
17+
1018Bugfixes
1119========
1220
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ Django 5.2.9 release notes
77Django 5.2.9 fixes one security issue with severity "high", one security issue
88with severity "moderate", and several bugs in 5.2.8.
99
10+ CVE-2025-13372: Potential SQL injection in ``FilteredRelation`` column aliases on PostgreSQL
11+ ============================================================================================
12+
13+ :class:`.FilteredRelation` was subject to SQL injection in column aliases,
14+ using a suitably crafted dictionary, with dictionary expansion, as the
15+ ``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias` on
16+ PostgreSQL.
17+
1018Bugfixes
1119========
1220
Original file line number Diff line number Diff line change @@ -1540,3 +1540,14 @@ def test_alias_filtered_relation_sql_injection(self):
15401540 )
15411541 with self .assertRaisesMessage (ValueError , msg ):
15421542 Book .objects .alias (** {crafted_alias : FilteredRelation ("authors" )})
1543+
1544+ def test_alias_filtered_relation_sql_injection_dollar_sign (self ):
1545+ qs = Book .objects .alias (
1546+ ** {"crafted_alia$" : FilteredRelation ("authors" )}
1547+ ).values ("name" , "crafted_alia$" )
1548+ if connection .vendor == "postgresql" :
1549+ msg = "Dollar signs are not permitted in column aliases on PostgreSQL."
1550+ with self .assertRaisesMessage (ValueError , msg ):
1551+ list (qs )
1552+ else :
1553+ self .assertEqual (qs .first ()["name" ], self .b1 .name )
You can’t perform that action at this time.
0 commit comments