Show the not found page for unknown URLs

A catch-all rule raises NotFound, so unknown URLs pass the middlewares
and get the regular not found page instead of Flask's default 404.
Anonymous visitors are redirected to the login like for any other URL,
so they cannot tell which URLs exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
finnandClaude Opus 5.5 committed 2026-10-22 18:37:12 +00:00
1 parent 105fd42d22
commit b1c412f3d7
1 file changed
+9
+9
View File
@@ -1,5 +1,6 @@
from max.auth import no_authentication_required from max.auth import no_authentication_required
from max.csrf import no_csrf from max.csrf import no_csrf
from max.exceptions import NotFound
from .alias.create import AliasCreate from .alias.create import AliasCreate
from .alias.delete import AliasDelete from .alias.delete import AliasDelete
@@ -21,6 +22,10 @@ from .user.toggle_can_use_different_alias_domain import (
from .user.toggle_enabled import UserToggleEnabled from .user.toggle_enabled import UserToggleEnabled
def not_found(**kwargs):
raise NotFound()
def init_routes(app): def init_routes(app):
app.add_url_rule("/", "own-user-detail", UserDetail.as_view()) app.add_url_rule("/", "own-user-detail", UserDetail.as_view())
app.add_url_rule("/list", "user-list", UserList.as_view()) app.add_url_rule("/list", "user-list", UserList.as_view())
@@ -78,3 +83,7 @@ def init_routes(app):
"favicon", "favicon",
no_csrf(no_authentication_required(Favicon.as_view())), no_csrf(no_authentication_required(Favicon.as_view())),
) )
# Matches only URLs without another rule. They pass the middlewares like any
# other view, so the ExceptionMiddleware renders the not found page.
app.add_url_rule("/<path:path>", "not-found", not_found)