1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-09-15 20:36:55 +00:00

Warning instead of error when base prefix ends with '/'

Workaround for #1210
This commit is contained in:
Unrud 2022-01-26 21:37:46 +01:00
parent 785659aa26
commit c296dfd497
2 changed files with 23 additions and 8 deletions

View file

@ -191,13 +191,16 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
base_prefix_src = ("HTTP_X_SCRIPT_NAME" if "HTTP_X_SCRIPT_NAME" in
environ else "SCRIPT_NAME")
base_prefix = environ.get(base_prefix_src, "")
if base_prefix and (base_prefix[0] != "/" or base_prefix[-1] == "/"):
logger.error("Base prefix (from %s) must %s with '/': %r",
base_prefix_src, "not end" if base_prefix[-1] == "/"
else "start", base_prefix)
if base_prefix and base_prefix[0] != "/":
logger.error("Base prefix (from %s) must start with '/': %r",
base_prefix_src, base_prefix)
if base_prefix_src == "HTTP_X_SCRIPT_NAME":
return response(*httputils.BAD_REQUEST)
return response(*httputils.INTERNAL_SERVER_ERROR)
if base_prefix.endswith("/"):
logger.warning("Base prefix (from %s) must not end with '/': %r",
base_prefix_src, base_prefix)
base_prefix = base_prefix.rstrip("/")
logger.debug("Base prefix (from %s): %r", base_prefix_src, base_prefix)
# Sanitize request URI (a WSGI server indicates with an empty path,
# that the URL targets the application root without a trailing slash)