diff --git a/README.md b/README.md index 80df3ce..11976eb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Stapler +![logo.svg](logo.svg) + ```txt usage: stapler [-h] [--debug | --no-debug] [-d DATA_DIR] [--certificates | --no-certificates] [--certbot | --no-certbot] [--self-signed-path SELF_SIGNED_PATH] [--certbot-conf CERTBOT_CONF] [--certbot-www CERTBOT_WWW] [--host HOST] [-p PORT] [--https | --no-https] [-t TOKEN] [--max-size-bytes MAX_SIZE] [-b BIND] @@ -96,7 +98,7 @@ curl -X DELETE \ - [x] create certificate on request - [x] certbot copy certificates for unique path - [x] better error page -- [ ] add favicon.ico + special path +- [x] add favicon.ico + special path - [ ] [http.server security](https://docs.python.org/3/library/http.server.html#http-server-security) - [ ] proper doc diff --git a/data/.gitignore b/data/.gitignore index c96a04f..e948666 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,2 +1,3 @@ * -!.gitignore \ No newline at end of file +!.gitignore +!favicon.ico \ No newline at end of file diff --git a/data/favicon.ico b/data/favicon.ico new file mode 100644 index 0000000..1b35660 Binary files /dev/null and b/data/favicon.ico differ diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..7484a30 --- /dev/null +++ b/logo.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/handler.py b/src/handler.py index a0bf881..9b97c81 100644 --- a/src/handler.py +++ b/src/handler.py @@ -20,6 +20,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): CERTBOT_CHALLENGE_PATH = "/.well-known/acme-challenge" PATH_REGEX = re.compile(r"^\/([\w-]+)\/") HOST_PART_REGEX = re.compile(r"^([a-zA-Z0-9]|[a-zA-Z0-9]*[a-zA-Z0-9][a-zA-Z0-9])$") + AUTHORIZED_PATHS: typing.ClassVar[list[str]] = ["/favicon.ico"] @typing.override def __init__( @@ -116,7 +117,9 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): return self.certbot_www + path.removeprefix(self.CERTBOT_CHALLENGE_PATH) if (page := self.registry.get_from_host(self.__get_host())) is not None: path = f"/{page.path}" + path - if self.__get_subpath(path) is None: # not a valid path + if ( + path not in self.AUTHORIZED_PATHS and self.__get_subpath(path) is None + ): # not a valid path return "" if pathlib.Path(path).name.startswith("."): # hidden files return ""