From 8ec00f08df4c6bc1605b44fdca75a77d5eb1ba29 Mon Sep 17 00:00:00 2001 From: deronnax Date: Tue, 21 Oct 2014 12:30:14 +0200 Subject: [PATCH] throw 401 in case of failed variable substition for .well-known url --- radicale/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 4a81d19..56d09b5 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -290,18 +290,19 @@ class Application(object): wkfragment = WELLKNOWNRE.match(path) if wkfragment: + if not user: del user redirect = config.get("well-known", wkfragment.group(1)) - if not user and "%(user)s" in redirect: + try: + redirect = redirect % locals() + status = client.SEE_OTHER + log.LOGGER.info("/.well-known/ redirection to: %s" % redirect) + headers = {"Location": redirect.encode('utf8')} + except KeyError: status = client.UNAUTHORIZED headers = { "WWW-Authenticate": "Basic realm=\"%s\"" % config.get("server", "realm")} log.LOGGER.info("refused /.well-known/ redirection to anonymous user") - else: - redirect = redirect % locals() - status = client.SEE_OTHER - log.LOGGER.info("/.well-known/ redirection to: %s" % redirect) - headers = {"Location": redirect.encode('utf8')} status = "%i %s" % (status, client.responses.get(status, "Unknown")) start_response(status, headers.items()) return []