Reject boolean power levels (#14944)

* Better test for bad values in power levels events

The previous test only checked that Synapse didn't raise an exception,
but didn't check that we had correctly interpreted the value of the
dodgy power level.

It also conflated two things: bad room notification levels, and bad user
levels. There _is_ logic for converting the latter to integers, but we
should test it separately.

* Check we ignore types that don't convert to int

* Handle `None` values in `notifications.room`

* Changelog

* Also test that bad values are rejected by event auth

* Docstring

* linter scripttttttttt

* Test boolean values in PL content

* Reject boolean power levels

* Changelog
This commit is contained in:
David Robertson 2023-01-31 10:57:02 +00:00 committed by GitHub
parent 796a4b7482
commit a134e626e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 6 deletions

View file

@ -875,11 +875,11 @@ def _check_power_levels(
"kick",
"invite",
}:
if not isinstance(v, int):
if type(v) is not int:
raise SynapseError(400, f"{v!r} must be an integer.")
if k in {"events", "notifications", "users"}:
if not isinstance(v, collections.abc.Mapping) or not all(
isinstance(v, int) for v in v.values()
type(v) is int for v in v.values()
):
raise SynapseError(
400,