diff options
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-django/CVE-2024-42005.patch | 84 | ||||
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-django_2.2.28.bb | 1 |
2 files changed, 85 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-django/CVE-2024-42005.patch b/meta-python/recipes-devtools/python/python3-django/CVE-2024-42005.patch new file mode 100644 index 0000000000..e6b58fca79 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-django/CVE-2024-42005.patch | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | From f4af67b9b41e0f4c117a8741da3abbd1c869ab28 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Simon Charette <charette.s@gmail.com> | ||
| 3 | Date: Thu, 25 Jul 2024 18:19:13 +0200 | ||
| 4 | Subject: [PATCH] Fixed CVE-2024-42005 -- Mitigated QuerySet.values() SQL | ||
| 5 | injection attacks against JSON fields. | ||
| 6 | |||
| 7 | Thanks Eyal (eyalgabay) for the report. | ||
| 8 | |||
| 9 | CVE: CVE-2024-42005 | ||
| 10 | |||
| 11 | Upstream-Status: Backport [https://github.com/django/django/commit/f4af67b9b41e0f4c117a8741da3abbd1c869ab28] | ||
| 12 | |||
| 13 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
| 14 | --- | ||
| 15 | django/db/models/sql/query.py | 2 ++ | ||
| 16 | tests/expressions/models.py | 7 +++++++ | ||
| 17 | tests/expressions/test_queryset_values.py | 17 +++++++++++++++-- | ||
| 18 | 3 files changed, 24 insertions(+), 2 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py | ||
| 21 | index 1e823cf..9b054bd 100644 | ||
| 22 | --- a/django/db/models/sql/query.py | ||
| 23 | +++ b/django/db/models/sql/query.py | ||
| 24 | @@ -2019,6 +2019,8 @@ class Query: | ||
| 25 | self.clear_select_fields() | ||
| 26 | |||
| 27 | if fields: | ||
| 28 | + for field in fields: | ||
| 29 | + self.check_alias(field) | ||
| 30 | field_names = [] | ||
| 31 | extra_names = [] | ||
| 32 | annotation_names = [] | ||
| 33 | diff --git a/tests/expressions/models.py b/tests/expressions/models.py | ||
| 34 | index 33f7850..fb80938 100644 | ||
| 35 | --- a/tests/expressions/models.py | ||
| 36 | +++ b/tests/expressions/models.py | ||
| 37 | @@ -97,3 +97,10 @@ class UUID(models.Model): | ||
| 38 | |||
| 39 | def __str__(self): | ||
| 40 | return "%s" % self.uuid | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +class JSONFieldModel(models.Model): | ||
| 44 | + data = models.JSONField(null=True) | ||
| 45 | + | ||
| 46 | + class Meta: | ||
| 47 | + required_db_features = {"supports_json_field"} | ||
| 48 | diff --git a/tests/expressions/test_queryset_values.py b/tests/expressions/test_queryset_values.py | ||
| 49 | index 0804531..bd52b8e 100644 | ||
| 50 | --- a/tests/expressions/test_queryset_values.py | ||
| 51 | +++ b/tests/expressions/test_queryset_values.py | ||
| 52 | @@ -1,8 +1,8 @@ | ||
| 53 | from django.db.models.aggregates import Sum | ||
| 54 | from django.db.models.expressions import F | ||
| 55 | -from django.test import TestCase | ||
| 56 | +from django.test import TestCase, skipUnlessDBFeature | ||
| 57 | |||
| 58 | -from .models import Company, Employee | ||
| 59 | +from .models import Company, Employee, JSONFieldModel | ||
| 60 | |||
| 61 | |||
| 62 | class ValuesExpressionsTests(TestCase): | ||
| 63 | @@ -36,6 +36,19 @@ class ValuesExpressionsTests(TestCase): | ||
| 64 | with self.assertRaisesMessage(ValueError, msg): | ||
| 65 | Company.objects.values(**{crafted_alias: F("ceo__salary")}) | ||
| 66 | |||
| 67 | + @skipUnlessDBFeature("supports_json_field") | ||
| 68 | + def test_values_expression_alias_sql_injection_json_field(self): | ||
| 69 | + crafted_alias = """injected_name" from "expressions_company"; --""" | ||
| 70 | + msg = ( | ||
| 71 | + "Column aliases cannot contain whitespace characters, quotation marks, " | ||
| 72 | + "semicolons, or SQL comments." | ||
| 73 | + ) | ||
| 74 | + with self.assertRaisesMessage(ValueError, msg): | ||
| 75 | + JSONFieldModel.objects.values(f"data__{crafted_alias}") | ||
| 76 | + | ||
| 77 | + with self.assertRaisesMessage(ValueError, msg): | ||
| 78 | + JSONFieldModel.objects.values_list(f"data__{crafted_alias}") | ||
| 79 | + | ||
| 80 | def test_values_expression_group_by(self): | ||
| 81 | # values() applies annotate() first, so values selected are grouped by | ||
| 82 | # id, not firstname. | ||
| 83 | -- | ||
| 84 | 2.40.0 | ||
diff --git a/meta-python/recipes-devtools/python/python3-django_2.2.28.bb b/meta-python/recipes-devtools/python/python3-django_2.2.28.bb index cbd2c69c05..7f5861f5d3 100644 --- a/meta-python/recipes-devtools/python/python3-django_2.2.28.bb +++ b/meta-python/recipes-devtools/python/python3-django_2.2.28.bb | |||
| @@ -11,6 +11,7 @@ SRC_URI += "file://CVE-2023-31047.patch \ | |||
| 11 | file://CVE-2023-43665.patch \ | 11 | file://CVE-2023-43665.patch \ |
| 12 | file://CVE-2023-46695.patch \ | 12 | file://CVE-2023-46695.patch \ |
| 13 | file://CVE-2024-24680.patch \ | 13 | file://CVE-2024-24680.patch \ |
| 14 | file://CVE-2024-42005.patch \ | ||
| 14 | " | 15 | " |
| 15 | 16 | ||
| 16 | SRC_URI[sha256sum] = "0200b657afbf1bc08003845ddda053c7641b9b24951e52acd51f6abda33a7413" | 17 | SRC_URI[sha256sum] = "0200b657afbf1bc08003845ddda053c7641b9b24951e52acd51f6abda33a7413" |
