summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2021-06-18 01:16:10 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-07-01 08:29:23 +0200
commita34a5f724c5d5adb2109374ba3989ebb7b11f81f (patch)
tree16a4b7fa2f0823a13aa324f69b62587f93205e4d /tests
parentda2269dc6f7daca090a28508dbd92207b6f639d0 (diff)
[3.2.x] Fixed CVE-2021-35042 -- Prevented SQL injection in QuerySet.order_by().
Regression introduced in 513948735b799239f3ef8c89397592445e1a0cd5 by marking the raw SQL column reference feature for deprecation in Django 4.0 while lifting the column format validation. In retrospective the validation should have been kept around and the user should have been pointed at using RawSQL expressions during the deprecation period. The main branch is not affected because the raw SQL column reference support has been removed in 06eec3197009b88e3a633128bbcbd76eea0b46ff per the 4.0 deprecation life cycle. Thanks Joel Saunders for the report.
Diffstat (limited to 'tests')
-rw-r--r--tests/queries/tests.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 877d758904..d487026e4d 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -3116,6 +3116,14 @@ class QuerySetExceptionTests(SimpleTestCase):
with self.assertRaisesMessage(FieldError, msg):
Article.objects.order_by('*')
+ def test_order_by_escape_prevention(self):
+ msg = (
+ "Cannot resolve keyword 'queries.name);' into field. Choices are: "
+ "created, id, name"
+ )
+ with self.assertRaisesMessage(FieldError, msg):
+ Article.objects.order_by('queries.name);')
+
def test_invalid_queryset_model(self):
msg = 'Cannot use QuerySet for "Article": Use a QuerySet for "ExtraInfo".'
with self.assertRaisesMessage(ValueError, msg):