1212 Exists ,
1313 ExpressionWrapper ,
1414 F ,
15+ FilteredRelation ,
1516 FloatField ,
1617 Func ,
1718 IntegerField ,
@@ -1132,6 +1133,15 @@ def test_alias_sql_injection(self):
11321133 with self .assertRaisesMessage (ValueError , msg ):
11331134 Book .objects .annotate (** {crafted_alias : Value (1 )})
11341135
1136+ def test_alias_filtered_relation_sql_injection (self ):
1137+ crafted_alias = """injected_name" from "annotations_book"; --"""
1138+ msg = (
1139+ "Column aliases cannot contain whitespace characters, quotation marks, "
1140+ "semicolons, or SQL comments."
1141+ )
1142+ with self .assertRaisesMessage (ValueError , msg ):
1143+ Book .objects .annotate (** {crafted_alias : FilteredRelation ("author" )})
1144+
11351145 def test_alias_forbidden_chars (self ):
11361146 tests = [
11371147 'al"ias' ,
@@ -1157,6 +1167,11 @@ def test_alias_forbidden_chars(self):
11571167 with self .assertRaisesMessage (ValueError , msg ):
11581168 Book .objects .annotate (** {crafted_alias : Value (1 )})
11591169
1170+ with self .assertRaisesMessage (ValueError , msg ):
1171+ Book .objects .annotate (
1172+ ** {crafted_alias : FilteredRelation ("authors" )}
1173+ )
1174+
11601175
11611176class AliasTests (TestCase ):
11621177 @classmethod
@@ -1429,3 +1444,12 @@ def test_alias_sql_injection(self):
14291444 )
14301445 with self .assertRaisesMessage (ValueError , msg ):
14311446 Book .objects .alias (** {crafted_alias : Value (1 )})
1447+
1448+ def test_alias_filtered_relation_sql_injection (self ):
1449+ crafted_alias = """injected_name" from "annotations_book"; --"""
1450+ msg = (
1451+ "Column aliases cannot contain whitespace characters, quotation marks, "
1452+ "semicolons, or SQL comments."
1453+ )
1454+ with self .assertRaisesMessage (ValueError , msg ):
1455+ Book .objects .alias (** {crafted_alias : FilteredRelation ("authors" )})
0 commit comments