Skip to content

Return 400, not 500, for malformed _search_ and _through params#2851

Open
santhreal wants to merge 1 commit into
simonw:mainfrom
santhreal:fix/filters-malformed-query-params-400
Open

Return 400, not 500, for malformed _search_ and _through params#2851
santhreal wants to merge 1 commit into
simonw:mainfrom
santhreal:fix/filters-malformed-query-params-400

Conversation

@santhreal

Copy link
Copy Markdown

Two malformed query-string parameters returned 500 instead of 400.

?_searchcol=x starts with _search but is not the ?_search_col= form, so key.split("_search_", 1)[1] raised IndexError; such keys are now ignored since they name no column. A malformed ?_through= value was passed straight to json.loads and then indexed, raising JSONDecodeError/KeyError/TypeError; it now raises BadRequest.

Adds tests for the malformed cases and confirms a valid column search still works.

Two filter hooks crashed with an unhandled 500 on malformed query strings:

- search_filters: a key that starts with _search but is not the
  _search_column= form (e.g. ?_searchcol=x) reached
  key.split("_search_", 1)[1] and raised IndexError. Such a key names
  no column, so skip it.

- through_filters: ?_through= was passed straight to json.loads() and
  indexed for table/column/value, so invalid JSON, a missing key, or a
  non-object value raised JSONDecodeError/KeyError/TypeError. Raise
  BadRequest instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant