From c756a9029aa7ac6111648602a9b0727476495e18 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 27 Jan 2024 19:46:52 -0500 Subject: [PATCH] authorization: don't raise config errors Don't raise an exception if the default source is incorrect as this disables authorization. Fallback to moonraker. When supplied an invalid CORS domain warn the user and skip adding it to the list. Signed-off-by: Eric Callahan --- moonraker/components/authorization.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/moonraker/components/authorization.py b/moonraker/components/authorization.py index a49309b..204c675 100644 --- a/moonraker/components/authorization.py +++ b/moonraker/components/authorization.py @@ -82,10 +82,12 @@ class Authorization: self.failed_logins: Dict[IPAddr, int] = {} self.fqdn_cache: Dict[IPAddr, Dict[str, Any]] = {} if self.default_source not in AUTH_SOURCES: - raise config.error( + self.server.add_warning( "[authorization]: option 'default_source' - Invalid " - f"value '{self.default_source}'" + f"value '{self.default_source}', falling back to " + "'moonraker'." ) + self.default_source = "moonraker" self.ldap: Optional[MoonrakerLDAP] = None if config.has_section("ldap"): self.ldap = self.server.load_component(config, "ldap", None) @@ -158,14 +160,18 @@ class Authorization: for domain in config.getlist('cors_domains', []): bad_match = re.search(r"^.+\.[^:]*\*", domain) if bad_match is not None: - raise config.error( - f"Unsafe CORS Domain '{domain}'. Wildcards are not" - " permitted in the top level domain.") + self.server.add_warning( + f"[authorization]: Unsafe domain '{domain}' in option " + f"'cors_domains'. Wildcards are not permitted in the" + " top level domain." + ) + continue if domain.endswith("/"): self.server.add_warning( f"[authorization]: Invalid domain '{domain}' in option " "'cors_domains'. Domain's cannot contain a trailing " - "slash.") + "slash." + ) else: self.cors_domains.append( domain.replace(".", "\\.").replace("*", ".*"))