Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3475: prevent malformed timestamps to reach storage queries #3477

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions kinto/core/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def delete(self):
obj = self._get_object_or_404(self.object_id)
self._raise_412_if_modified(obj)

# Retreive the last_modified information from a querystring if present.
# Retrieve the last_modified information from a querystring if present.
last_modified = self.request.validated["querystring"].get("last_modified")

# If less or equal than current object. Ignore it.
Expand Down Expand Up @@ -1060,7 +1060,8 @@ def _extract_filters(self):
"""Extracts filters from QueryString parameters."""

def is_valid_timestamp(value):
return isinstance(value, int) or re.match(r'^"?\d+"?$', str(value))
# Is either integer, or integer as string, or integer between 2 quotes.
return isinstance(value, int) or re.match(r'^(\d+)$|^("\d+")$', str(value))

queryparams = self.request.validated["querystring"]

Expand Down
4 changes: 4 additions & 0 deletions tests/core/resource/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def test_filter_raises_error_if_last_modified_value_is_not_int(self):
self.validated["querystring"] = {"lt_last_modified": bad_value}
self.assertRaises(httpexceptions.HTTPBadRequest, self.resource.plural_get)

def test_filter_raises_error_if_last_modified_value_has_malformed_quotes(self):
self.validated["querystring"] = {"last_modified": '123"'}
self.assertRaises(httpexceptions.HTTPBadRequest, self.resource.plural_get)

def test_filter_works_with_since_none(self):
self.validated["querystring"] = {"_since": None}
result = self.resource.plural_get()
Expand Down
Loading