mirror of
https://github.com/django/django.git
synced 2025-09-11 13:06:29 +00:00
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.
This commit is contained in:
parent
4b78420d25
commit
7deeabc7c7
7 changed files with 59 additions and 8 deletions
|
@ -5,9 +5,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 Count, 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 PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||
|
@ -331,6 +332,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(PostgreSQLSimpleTestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue