Skip to content

Commit

Permalink
make sure there are no null bytes in input data from query strings (w…
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes authored and gasman committed Jun 24, 2024
1 parent ad95e0a commit 7779176
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Changelog
* Fix: Handle choice groups as dictionaries in active filters (Sébastien Corbin)
* Fix: Add separators when displaying multiple error messages on a StructBlock (Kyle Bayliss)
* Fix: Specify `verbose_name` on `TranslatableMixin.locale` so that it is translated when used as a label (Romein van Buren)
* Fix: Disallow null characters in API filter values (Jochen Wersdörfer)
* Docs: Remove duplicate section on frontend caching proxies from performance page (Jake Howard)
* Docs: Document `restriction_type` field on PageViewRestriction (Shlomo Markowitz)
* Docs: Document Wagtail's bug bounty policy (Jake Howard)
Expand Down
1 change: 1 addition & 0 deletions docs/releases/6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ depth: 1
* Fix the rendering of grouped choices when using ChoiceFilter in combination with choices (Sébastien Corbin)
* Add separators when displaying multiple error messages on a StructBlock (Kyle Bayliss)
* Specify `verbose_name` on `TranslatableMixin.locale` so that it is translated when used as a label (Romein van Buren)
* Disallow null characters in API filter values (Jochen Wersdörfer)


### Documentation
Expand Down
6 changes: 6 additions & 0 deletions wagtail/api/v2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def filter_queryset(self, request, queryset, view):
% (value, field_name, str(e))
)

if "\x00" in str(value):
raise BadRequestError(
"field filter error. null characters are not allowed for %s"
% field_name
)

if isinstance(field, TaggableManager):
for tag in value.split(","):
queryset = queryset.filter(**{field_name + "__name": tag})
Expand Down
10 changes: 10 additions & 0 deletions wagtail/api/v2/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,16 @@ def test_filtering_boolean_validation(self):
},
)

def test_slug_field_containing_null_bytes_gives_error(self):
response = self.get_response(slug="\0")
content = json.loads(response.content.decode("UTF-8"))

self.assertEqual(response.status_code, 400)
self.assertEqual(
content,
{"message": "field filter error. null characters are not allowed for slug"},
)

# CHILD OF FILTER

def test_child_of_filter(self):
Expand Down

0 comments on commit 7779176

Please sign in to comment.