summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_json.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-22 10:45:26 +0200
committerCarlton Gibson <carlton.gibson@noumenal.es>2019-07-31 12:43:32 +0200
commitf74b3ae3628c26e1b4f8db3d13a91d52a833a975 (patch)
treec3ac9d6ff511cadc464f120e814a6d44de7ab8d6 /tests/postgres_tests/test_json.py
parent5ff8e791148bd451180124d76a55cb2b2b9556eb (diff)
[2.1.x] Fixed CVE-2019-14234 -- Protected JSONField/HStoreField key and index lookups against SQL injection.
Thanks to Sage M. Abdullah for the report and initial patch. Thanks Florian Apolloner for reviews.
Diffstat (limited to 'tests/postgres_tests/test_json.py')
-rw-r--r--tests/postgres_tests/test_json.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py
index 2f0b55a292..e58c7a2e7f 100644
--- a/tests/postgres_tests/test_json.py
+++ b/tests/postgres_tests/test_json.py
@@ -4,9 +4,10 @@ from decimal import Decimal
from django.core import checks, exceptions, serializers
from django.core.serializers.json import DjangoJSONEncoder
+from django.db import connection
from django.db.models import Q
from django.forms import CharField, Form, widgets
-from django.test.utils import isolate_apps
+from django.test.utils import CaptureQueriesContext, isolate_apps
from django.utils.html import escape
from . import PostgreSQLTestCase
@@ -299,6 +300,18 @@ class TestQuerying(PostgreSQLTestCase):
def test_iregex(self):
self.assertTrue(JSONModel.objects.filter(field__foo__iregex=r'^bAr$').exists())
+ def test_key_sql_injection(self):
+ with CaptureQueriesContext(connection) as queries:
+ self.assertFalse(
+ JSONModel.objects.filter(**{
+ """field__test' = '"a"') OR 1 = 1 OR ('d""": 'x',
+ }).exists()
+ )
+ self.assertIn(
+ """."field" -> 'test'' = ''"a"'') OR 1 = 1 OR (''d') = '"x"' """,
+ queries[0]['sql'],
+ )
+
@isolate_apps('postgres_tests')
class TestChecks(PostgreSQLTestCase):