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

Commit

Permalink
Validation for public_baseurl
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Oct 29, 2021
1 parent f34df89 commit 3ed765a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os.path
import re
import urllib.parse
from textwrap import indent
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Union

Expand Down Expand Up @@ -288,6 +289,20 @@ def read_config(self, config, **kwargs):
public_baseurl += "/"
self.public_baseurl = public_baseurl

# check that public_baseurl is valid
try:
splits = urllib.parse.urlsplit(self.public_baseurl)
except Exception as e:
raise ConfigError(f"Unable to parse URL: {e}", ("public_baseurl",))
if splits.scheme not in ("https", "http"):
raise ConfigError(
f"Invalid scheme '{splits.scheme}': only https and http are supported"
)
if splits.query or splits.fragment:
raise ConfigError(
"public_baseurl cannot contain query parameters or a #-fragment"
)

# Whether to enable user presence.
presence_config = config.get("presence") or {}
self.use_presence = presence_config.get("enabled")
Expand Down

0 comments on commit 3ed765a

Please sign in to comment.