Validate group ids when parsing

May as well do it whenever we parse a Group ID. We check the sigil and basic
structure here so it makes sense to check the grammar in the same place.
This commit is contained in:
Richard van der Hoff 2017-10-20 23:51:07 +01:00
parent 29812c628b
commit 1135193dfd
3 changed files with 45 additions and 17 deletions

View file

@ -161,6 +161,23 @@ class GroupID(DomainSpecificString):
"""Structure representing a group ID."""
SIGIL = "+"
@classmethod
def from_string(cls, s):
group_id = super(GroupID, cls).from_string(s)
if not group_id.localpart:
raise SynapseError(
400,
"Group ID cannot be empty",
)
if contains_invalid_mxid_characters(group_id.localpart):
raise SynapseError(
400,
"Group ID can only contain characters a-z, 0-9, or '=_-./'",
)
return group_id
mxid_localpart_allowed_characters = set("_-./=" + string.ascii_lowercase + string.digits)