1414 Exists ,
1515 ExpressionWrapper ,
1616 F ,
17+ FilteredRelation ,
1718 FloatField ,
1819 Func ,
1920 IntegerField ,
@@ -1164,6 +1165,15 @@ def test_alias_sql_injection(self):
11641165 with self .assertRaisesMessage (ValueError , msg ):
11651166 Book .objects .annotate (** {crafted_alias : Value (1 )})
11661167
1168+ def test_alias_filtered_relation_sql_injection (self ):
1169+ crafted_alias = """injected_name" from "annotations_book"; --"""
1170+ msg = (
1171+ "Column aliases cannot contain whitespace characters, quotation marks, "
1172+ "semicolons, or SQL comments."
1173+ )
1174+ with self .assertRaisesMessage (ValueError , msg ):
1175+ Book .objects .annotate (** {crafted_alias : FilteredRelation ("author" )})
1176+
11671177 def test_alias_forbidden_chars (self ):
11681178 tests = [
11691179 'al"ias' ,
@@ -1189,6 +1199,11 @@ def test_alias_forbidden_chars(self):
11891199 with self .assertRaisesMessage (ValueError , msg ):
11901200 Book .objects .annotate (** {crafted_alias : Value (1 )})
11911201
1202+ with self .assertRaisesMessage (ValueError , msg ):
1203+ Book .objects .annotate (
1204+ ** {crafted_alias : FilteredRelation ("authors" )}
1205+ )
1206+
11921207 @skipUnless (connection .vendor == "postgresql" , "PostgreSQL tests" )
11931208 @skipUnlessDBFeature ("supports_json_field" )
11941209 def test_set_returning_functions (self ):
@@ -1482,3 +1497,12 @@ def test_alias_sql_injection(self):
14821497 )
14831498 with self .assertRaisesMessage (ValueError , msg ):
14841499 Book .objects .alias (** {crafted_alias : Value (1 )})
1500+
1501+ def test_alias_filtered_relation_sql_injection (self ):
1502+ crafted_alias = """injected_name" from "annotations_book"; --"""
1503+ msg = (
1504+ "Column aliases cannot contain whitespace characters, quotation marks, "
1505+ "semicolons, or SQL comments."
1506+ )
1507+ with self .assertRaisesMessage (ValueError , msg ):
1508+ Book .objects .alias (** {crafted_alias : FilteredRelation ("authors" )})
0 commit comments