add error handling for policy configuration issues in authentication

This commit is contained in:
Eduardo Silva
2026-03-16 14:16:28 -03:00
parent e1f128f217
commit c707d278f3
5 changed files with 11 additions and 6 deletions

View File

@@ -23,6 +23,8 @@ async def auth_check(request: Request):
return PlainTextResponse("Application was not found.", status_code=403)
effective_policy = get_effective_policy(runtime_config, context.policy_name)
if effective_policy.mode == "error":
return PlainTextResponse(effective_policy.error_message or "Policy configuration error.", status_code=500)
if effective_policy.mode == "deny":
return PlainTextResponse("Access denied by policy.", status_code=403)
if effective_policy.mode == "bypass":

View File

@@ -64,6 +64,8 @@ async def login_page(request: Request, next: str = "/"):
context = resolve_context_from_request(request, runtime_config, next)
effective_policy = get_effective_policy(runtime_config, context.policy_name)
if effective_policy.mode == "error":
return _render(request, "error.html", status_code=500, title="Configuration error", message=effective_policy.error_message or "A policy configuration error has been detected.")
if effective_policy.mode == "deny":
return _render(request, "error.html", status_code=403, title="Access denied", message="This route is blocked by policy.")
if effective_policy.mode == "bypass":