mirror of
https://github.com/django/django.git
synced 2025-08-30 23:37:50 +00:00
Fixed CVE-2022-28346 -- Protected QuerySet.annotate(), aggregate(), and extra() against SQL injection in column aliases.
Thanks Splunk team: Preston Elder, Jacob Davis, Jacob Moore, Matt Hanson, David Briggs, and a security researcher: Danylo Dmytriiev (DDV_UA) for the report.
This commit is contained in:
parent
62739b6e26
commit
93cae5cb2f
8 changed files with 108 additions and 0 deletions
|
@ -34,6 +34,15 @@ class ValuesExpressionsTests(TestCase):
|
|||
[{"salary": 10}, {"salary": 20}, {"salary": 30}],
|
||||
)
|
||||
|
||||
def test_values_expression_alias_sql_injection(self):
|
||||
crafted_alias = """injected_name" from "expressions_company"; --"""
|
||||
msg = (
|
||||
"Column aliases cannot contain whitespace characters, quotation marks, "
|
||||
"semicolons, or SQL comments."
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Company.objects.values(**{crafted_alias: F("ceo__salary")})
|
||||
|
||||
def test_values_expression_group_by(self):
|
||||
# values() applies annotate() first, so values selected are grouped by
|
||||
# id, not firstname.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue