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

Commit

Permalink
Check if instances are lists, not sequences. (#12128)
Browse files Browse the repository at this point in the history
As a str is a sequence, the checks were not granular
enough and would allow lists or strings, when only
lists were valid.
  • Loading branch information
clokep authored Mar 2, 2022
1 parent f3f0ab1 commit 1103c5f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/12128.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix data validation to compare to lists, not sequences.
8 changes: 4 additions & 4 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ async def send_request(

# Validate children_state of the room.
children_state = room.pop("children_state", [])
if not isinstance(children_state, Sequence):
if not isinstance(children_state, list):
raise InvalidResponseError("'room.children_state' must be a list")
if any(not isinstance(e, dict) for e in children_state):
raise InvalidResponseError("Invalid event in 'children_state' list")
Expand All @@ -1440,14 +1440,14 @@ async def send_request(

# Validate the children rooms.
children = res.get("children", [])
if not isinstance(children, Sequence):
if not isinstance(children, list):
raise InvalidResponseError("'children' must be a list")
if any(not isinstance(r, dict) for r in children):
raise InvalidResponseError("Invalid room in 'children' list")

# Validate the inaccessible children.
inaccessible_children = res.get("inaccessible_children", [])
if not isinstance(inaccessible_children, Sequence):
if not isinstance(inaccessible_children, list):
raise InvalidResponseError("'inaccessible_children' must be a list")
if any(not isinstance(r, str) for r in inaccessible_children):
raise InvalidResponseError(
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def _validate_hierarchy_event(d: JsonDict) -> None:
raise ValueError("Invalid event: 'content' must be a dict")

via = content.get("via")
if not isinstance(via, Sequence):
if not isinstance(via, list):
raise ValueError("Invalid event: 'via' must be a list")
if any(not isinstance(v, str) for v in via):
raise ValueError("Invalid event: 'via' must be a list of strings")
2 changes: 1 addition & 1 deletion synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def as_json(self) -> JsonDict:

def _has_valid_via(e: EventBase) -> bool:
via = e.content.get("via")
if not via or not isinstance(via, Sequence):
if not via or not isinstance(via, list):
return False
for v in via:
if not isinstance(v, str):
Expand Down

0 comments on commit 1103c5f

Please sign in to comment.