summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_hstore.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-29 11:06:54 +0200
commit4f5b58f5cd3c57fee9972ab074f8dc6895d8f387 (patch)
treed5c88f2c511f9edea707d7d020de1d234f9d41f2 /tests/postgres_tests/test_hstore.py
parente34f3c0e9ee5fc9022428fe91640638bafd4cda7 (diff)
[2.2.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_hstore.py')
-rw-r--r--tests/postgres_tests/test_hstore.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
index 1d7403fb20..29936e297e 100644
--- a/tests/postgres_tests/test_hstore.py
+++ b/tests/postgres_tests/test_hstore.py
@@ -1,8 +1,9 @@
import json
from django.core import checks, exceptions, serializers
+from django.db import connection
from django.forms import Form
-from django.test.utils import isolate_apps
+from django.test.utils import CaptureQueriesContext, isolate_apps
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
from .models import HStoreModel, PostgreSQLModel
@@ -185,6 +186,18 @@ class TestQuerying(PostgreSQLTestCase):
self.objs[:2]
)
+ def test_key_sql_injection(self):
+ with CaptureQueriesContext(connection) as queries:
+ self.assertFalse(
+ HStoreModel.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(PostgreSQLSimpleTestCase):