mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
UX: Improve error handling for DiscourseConnect (#26140)
Previously, if the sso= payload was invalid Base64, but signed correctly, there would be no useful log or error. This commit improves things by: - moving the base64 check before the signature checking so that it's properly surfaced - split the ParseError exception into PayloadParseError and SignatureError - add user-facing errors for both of those - add/improve spec for both
This commit is contained in:
@ -168,13 +168,19 @@ class SessionController < ApplicationController
|
||||
|
||||
begin
|
||||
sso = DiscourseConnect.parse(request.query_string, secure_session: secure_session)
|
||||
rescue DiscourseConnect::ParseError => e
|
||||
rescue DiscourseConnect::PayloadParseError => e
|
||||
connect_verbose_warn do
|
||||
"Verbose SSO log: Signature parse error\n\n#{e.message}\n\n#{sso&.diagnostics}"
|
||||
"Verbose SSO log: Payload is not base64\n\n#{e.message}\n\n#{sso&.diagnostics}"
|
||||
end
|
||||
|
||||
return render_sso_error(text: I18n.t("discourse_connect.payload_parse_error"), status: 422)
|
||||
rescue DiscourseConnect::SignatureError => e
|
||||
connect_verbose_warn do
|
||||
"Verbose SSO log: Signature verification failed\n\n#{e.message}\n\n#{sso&.diagnostics}"
|
||||
end
|
||||
|
||||
# Do NOT pass the error text to the client, it would give them the correct signature
|
||||
return render_sso_error(text: I18n.t("discourse_connect.login_error"), status: 422)
|
||||
return render_sso_error(text: I18n.t("discourse_connect.signature_error"), status: 422)
|
||||
end
|
||||
|
||||
if !sso.nonce_valid?
|
||||
|
Reference in New Issue
Block a user