mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 06:24:49 -04:00
Sanity check identity server passed to bind/unbind. (#9802)
Signed-off-by: Denis Kasak <dkasak@termina.org.uk>
This commit is contained in:
parent
2b7dd21655
commit
e694a598f8
3 changed files with 59 additions and 3 deletions
|
@ -132,6 +132,38 @@ def parse_and_validate_server_name(server_name: str) -> Tuple[str, Optional[int]
|
|||
return host, port
|
||||
|
||||
|
||||
def valid_id_server_location(id_server: str) -> bool:
|
||||
"""Check whether an identity server location, such as the one passed as the
|
||||
`id_server` parameter to `/_matrix/client/r0/account/3pid/bind`, is valid.
|
||||
|
||||
A valid identity server location consists of a valid hostname and optional
|
||||
port number, optionally followed by any number of `/` delimited path
|
||||
components, without any fragment or query string parts.
|
||||
|
||||
Args:
|
||||
id_server: identity server location string to validate
|
||||
|
||||
Returns:
|
||||
True if valid, False otherwise.
|
||||
"""
|
||||
|
||||
components = id_server.split("/", 1)
|
||||
|
||||
host = components[0]
|
||||
|
||||
try:
|
||||
parse_and_validate_server_name(host)
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
if len(components) < 2:
|
||||
# no path
|
||||
return True
|
||||
|
||||
path = components[1]
|
||||
return "#" not in path and "?" not in path
|
||||
|
||||
|
||||
def parse_and_validate_mxc_uri(mxc: str) -> Tuple[str, Optional[int], str]:
|
||||
"""Parse the given string as an MXC URI
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue