[BUG]: Missing error handlers for oidc failure cause 500 Server Error #289
Labels
No labels
bug
duplicate
enhancement
help wanted
high priority
invalid
L
low priority
M
medium priority
needs refinement
question
S
UX research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: local-it/mitgliederverwaltung#289
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
AuthController: Missing error handlers for Assent errors cause 500 Server Error
Description
When the OIDC server (Rauthy) is unreachable or there's a configuration error (e.g., invalid
client_secret), the application throws aFunctionClauseErrorand returns a 500 error instead of a user-friendly error message.Root Cause
The
handle_rauthy_failure/2function inMvWeb.AuthControlleronly has pattern matches for:%Ash.Error.Invalid{}%AshAuthentication.Errors.AuthenticationFailed{}It does not handle Assent-specific errors:
%Assent.ServerUnreachableError{}- OIDC server is offline/unreachable%Assent.InvalidResponseError{}- OIDC server returns an error (401, 403, etc.)Steps to Reproduce
Scenario 1: Server unreachable
docker compose stop rauthyFunctionClauseErrorScenario 2: Invalid configuration
client_secretin.envExpected Behavior
User-friendly error message like "The authentication server is currently unavailable. Please try again later." with redirect to sign-in page.
Actual Behavior
** (FunctionClauseError) no function clause matching in MvWeb.AuthController.handle_rauthy_failure/2
Proposed Solution
Add catch-all handler and/or specific handlers for Assent errors in
handle_rauthy_failure/2:ixir
Handle server unreachable
defp handle_rauthy_failure(conn, %Assent.ServerUnreachableError{request_url: url}) do
Logger.error("OIDC server unreachable: #{url}")
redirect_with_error(conn, gettext("The authentication server is currently unavailable. Please try again later."))
end
Handle invalid response (e.g., wrong client_secret, 401/403)
defp handle_rauthy_failure(conn, %Assent.InvalidResponseError{response: response}) do
Logger.error("OIDC invalid response: #{inspect(response.body)}")
redirect_with_error(conn, gettext("Authentication configuration error. Please contact the administrator."))
end
Catch-all for any other unexpected errors
defp handle_rauthy_failure(conn, reason) do
Logger.error("Unexpected OIDC error: #{inspect(reason)}")
redirect_with_error(conn, gettext("Unable to authenticate with OIDC. Please try again."))
end### Affected File
lib/mv_web/controllers/auth_controller.ex(lines 64-79)