Skip to content

Commit

Permalink
fix(oidc): prompt none not handled (#7018)
Browse files Browse the repository at this point in the history
This fixes an issue where prompt type none could be handled properly in a couple of scenarios but wasn't.

Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
  • Loading branch information
james-d-elliott committed Mar 25, 2024
1 parent 2ebc04f commit 680546b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/handlers/handler_oidc_authorization.go
Expand Up @@ -18,6 +18,8 @@ import (
// OpenIDConnectAuthorization handles GET/POST requests to the OpenID Connect 1.0 Authorization endpoint.
//
// https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
//
//nolint:gocyclo
func OpenIDConnectAuthorization(ctx *middlewares.AutheliaCtx, rw http.ResponseWriter, r *http.Request) {
var (
requester oauthelia2.AuthorizeRequester
Expand All @@ -42,6 +44,10 @@ func OpenIDConnectAuthorization(ctx *middlewares.AutheliaCtx, rw http.ResponseWr
return
}

if requester.GetResponseMode() == oidc.ResponseModeFormPost {
ctx.SetUserValue(middlewares.UserValueKeyOpenIDConnectResponseModeFormPost, true)
}

clientID := requester.GetClient().GetID()

ctx.Logger.Debugf("Authorization Request with id '%s' on client with id '%s' is being processed", requester.GetID(), clientID)
Expand Down Expand Up @@ -82,6 +88,24 @@ func OpenIDConnectAuthorization(ctx *middlewares.AutheliaCtx, rw http.ResponseWr
return
}

if requester.GetRequestForm().Get(oidc.FormParameterPrompt) == oidc.PromptNone {
if userSession.IsAnonymous() {
ctx.Logger.Errorf("Authorization Request with id '%s' on client with id '%s' could not be processed: the 'prompt' type of 'none' was requested but the user is not logged in", requester.GetID(), client.GetID())

ctx.Providers.OpenIDConnect.WriteAuthorizeError(ctx, rw, requester, oauthelia2.ErrLoginRequired)

return
}

if client.GetConsentPolicy().Mode == oidc.ClientConsentModeExplicit {
ctx.Logger.Errorf("Authorization Request with id '%s' on client with id '%s' could not be processed: the 'prompt' type of 'none' was requested but client is configured to require explicit consent", requester.GetID(), client.GetID())

ctx.Providers.OpenIDConnect.WriteAuthorizeError(ctx, rw, requester, oauthelia2.ErrConsentRequired)

return
}
}

issuer = ctx.RootURL()

if consent, handled = handleOIDCAuthorizationConsent(ctx, issuer, client, userSession, rw, r, requester); handled {
Expand Down
Expand Up @@ -121,6 +121,14 @@ func handleOIDCAuthorizationConsentModePreConfiguredWithID(ctx *middlewares.Auth
return nil, true
}

if requester.GetRequestForm().Get(oidc.FormParameterPrompt) == oidc.PromptNone {
ctx.Logger.Errorf("Authorization Request with id '%s' on client with id '%s' could not be processed: the 'prompt' type of 'none' was requested but client is configured to require consent or pre-configured consent and the pre-configured consent was absent", requester.GetID(), client.GetID())

ctx.Providers.OpenIDConnect.WriteAuthorizeError(ctx, rw, requester, oauthelia2.ErrConsentRequired)

return nil, true
}

return consent, false
}

Expand All @@ -141,6 +149,14 @@ func handleOIDCAuthorizationConsentModePreConfiguredWithoutID(ctx *middlewares.A
}

if config == nil {
if requester.GetRequestForm().Get(oidc.FormParameterPrompt) == oidc.PromptNone {
ctx.Logger.Errorf("Authorization Request with id '%s' on client with id '%s' could not be processed: the 'prompt' type of 'none' was requested but client is configured to require consent or pre-configured consent and the pre-configured consent was absent", requester.GetID(), client.GetID())

ctx.Providers.OpenIDConnect.WriteAuthorizeError(ctx, rw, requester, oauthelia2.ErrConsentRequired)

return nil, true
}

return handleOIDCAuthorizationConsentGenerate(ctx, issuer, client, userSession, subject, rw, r, requester)
}

Expand Down
1 change: 1 addition & 0 deletions internal/oidc/const.go
Expand Up @@ -163,6 +163,7 @@ const (
FormParameterResponseType = "response_type"
FormParameterScope = valueScope
FormParameterIssuer = valueIss
FormParameterPrompt = "prompt"
)

const (
Expand Down

0 comments on commit 680546b

Please sign in to comment.