1 parent
94408fd2dd
commit
c7dee8d67d
4 files changed
+57
-20
No files matched your search
@@ -207,3 +207,6 @@ class ServerConfig(BaseModel):
|
||||
|
||||
cookies: CookiesConfig = CookiesConfig()
|
||||
"""Settings for further configuration of the cookies that OctoPrint sets (login, remember me, ...)."""
|
||||
|
||||
allowedLoginRedirectPaths: List[str] = []
|
||||
"""List of paths that are allowed to be used as redirect targets for the login page, in addition to the default ones (`/`, `/recovery/` and `/plugin/appkeys/auth/`)"""
|
||||
@@ -452,7 +452,7 @@ def validate_local_redirect(url, allowed_paths):
|
||||
Args:
|
||||
url (str): URL to validate
|
||||
allowed_paths (List[str]): List of allowed paths, only paths contained
|
||||
will be considered valid.
|
||||
or prefixed (if allowed path ends with "*") will be considered valid.
|
||||
|
||||
Returns:
|
||||
bool: Whether the `url` passed validation or not.
|
||||
@@ -460,4 +460,15 @@ def validate_local_redirect(url, allowed_paths):
|
||||
from urllib.parse import urlparse
|
||||
|
||||
parsed = urlparse(url)
|
||||
return parsed.scheme == "" and parsed.netloc == "" and parsed.path in allowed_paths
|
||||
return (
|
||||
parsed.scheme == ""
|
||||
and parsed.netloc == ""
|
||||
and any(
|
||||
map(
|
||||
lambda x: parsed.path.startswith(x[:-1])
|
||||
if x.endswith("*")
|
||||
else parsed.path == x,
|
||||
allowed_paths,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -181,7 +181,22 @@ def login():
|
||||
|
||||
default_redirect_url = request.script_root + url_for("index")
|
||||
redirect_url = request.args.get("redirect", default_redirect_url)
|
||||
allowed_paths = [url_for("index"), url_for("recovery")]
|
||||
|
||||
configured_allowed_paths = settings().get(["server", "allowedLoginRedirectPaths"])
|
||||
if configured_allowed_paths is None or not isinstance(configured_allowed_paths, list):
|
||||
configured_allowed_paths = []
|
||||
configured_allowed_paths = list(
|
||||
filter(
|
||||
lambda x: isinstance(x, str),
|
||||
configured_allowed_paths,
|
||||
)
|
||||
)
|
||||
|
||||
allowed_paths = [
|
||||
url_for("index"),
|
||||
url_for("recovery"),
|
||||
url_for("plugin.appkeys.handle_auth_dialog", app_token="*"),
|
||||
] + configured_allowed_paths
|
||||
|
||||
if not validate_local_redirect(redirect_url, allowed_paths):
|
||||
_logger.warning(
|
||||
|
||||
Reference in new issue
Block a user