Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

"Invalid filter json" error message should use an appropriate error code #13661

Closed
DMRobertson opened this issue Aug 30, 2022 · 2 comments · Fixed by #14262
Closed

"Invalid filter json" error message should use an appropriate error code #13661

DMRobertson opened this issue Aug 30, 2022 · 2 comments · Fixed by #14262
Labels
A-Sync defects related to /sync A-Validation 500 (mostly) errors due to lack of event/parameter validation good first issue Good for newcomers O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. Z-Cleanup Things we want to get rid of, but aren't actively causing pain

Comments

@DMRobertson
Copy link
Contributor

{
  "errcode": "M_UNKNOWN",
  "error": "Invalid filter JSON"
}

From

elif filter_id.startswith("{"):
try:
filter_object = json_decoder.decode(filter_id)
set_timeline_upper_limit(
filter_object, self.hs.config.server.filter_timeline_limit
)
except Exception:
raise SynapseError(400, "Invalid filter JSON")
self.filtering.check_valid_filter(filter_object)
filter_collection = FilterCollection(self.hs, filter_object)

We should return M_NOT_JSON if the decode fails.

We should probably also defer the set_timeline_upper_limit call until self.filtering.check_valid_filter(filter_object) has passed?

@DMRobertson DMRobertson added A-Validation 500 (mostly) errors due to lack of event/parameter validation A-Sync defects related to /sync good first issue Good for newcomers S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. O-Uncommon Most users are unlikely to come across this or unexpected workflow Z-Cleanup Things we want to get rid of, but aren't actively causing pain labels Aug 30, 2022
@shraddhafalane
Copy link

I would like to work on it. @DMRobertson could you please elaborate more on defer logic.

@DMRobertson
Copy link
Contributor Author

I would like to work on it. @DMRobertson could you please elaborate more on defer logic.

I was thinking that we should move lines 148-150 outside of the try block, because they do not related to the decoding of JSON. Probably between lines 153 and 154. But this isn't a hugely important change to make.

DMRobertson pushed a commit that referenced this issue Oct 24, 2022
#14262)

* Return NOT_JSON if decode fails and defer set_timeline_upper_limit call until after check_valid_filter. Fixes #13661. Signed-off-by: Ryan Miguel <miguel.ryanj@gmail.com>.

* Reword changelog
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Sync defects related to /sync A-Validation 500 (mostly) errors due to lack of event/parameter validation good first issue Good for newcomers O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. Z-Cleanup Things we want to get rid of, but aren't actively causing pain
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants