fix: /authorize endpoint crashes when list of scopes is empty (#1575)

This commit is contained in:
Alessandro (Ale) Segala
2026-07-08 17:48:32 -07:00
committed by GitHub
parent 6734585712
commit b2711ced99
7 changed files with 78 additions and 15 deletions
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"log/slog"
"maps"
"net/url"
"slices"
"strconv"
@@ -451,15 +452,18 @@ func (r interactionRequirements) any() bool {
func (s *authorizationService) createInteractionSession(ctx context.Context, requester fosite.AuthorizeRequester, requestParams map[string]string, userID string, requirements interactionRequirements) (InteractionSession, error) {
parameters := make(map[string]string, len(requestParams))
for key, value := range requestParams {
parameters[key] = value
maps.Copy(parameters, requestParams)
scopes := requester.GetRequestedScopes()
if scopes == nil {
scopes = []string{}
}
return s.interactionSessionService.create(ctx, InteractionSession{
Base: model.Base{
ID: requester.GetID(),
},
Scopes: datatype.StringList(requester.GetRequestedScopes()),
Scopes: datatype.StringList(scopes),
ClientID: requester.GetClient().GetID(),
UserID: utils.PtrOrNil(userID),
ConsentRequired: requirements.ConsentRequired,
+7 -2
View File
@@ -187,8 +187,13 @@ func (s *deviceService) getDeviceCodeInfo(ctx context.Context, userCode, userID
authorizationRequired = consentRequired(hasAuthorizedClient, client.SkipConsent, nil)
}
scope := request.GetRequestedScopes()
if scope == nil {
scope = []string{}
}
// Resolve friendly names for the requested custom-API permissions so the device consent screen matches the browser flow
scopeInfo, err := s.authorizationService.resolveScopeInfoForRequest(ctx, resource, request.GetRequestedScopes())
scopeInfo, err := s.authorizationService.resolveScopeInfoForRequest(ctx, resource, scope)
if err != nil {
return nil, err
}
@@ -206,7 +211,7 @@ func (s *deviceService) getDeviceCodeInfo(ctx context.Context, userCode, userID
LaunchURL: client.LaunchURL,
RequiresReauthentication: client.RequiresReauthentication,
},
Scope: request.GetRequestedScopes(),
Scope: scope,
ScopeInfo: scopeInfo,
AuthorizationRequired: authorizationRequired,
ReauthenticationRequired: client.RequiresReauthentication,
@@ -43,9 +43,17 @@ func newInteractionSessionForUser(interactionSession InteractionSession) (intera
currentStep = requiredSteps[0]
}
scopes := interactionSession.Scopes
if scopes == nil {
scopes = []string{}
}
if requiredSteps == nil {
requiredSteps = []interactionStep{}
}
return interactionSessionForUser{
ID: interactionSession.ID,
Scopes: interactionSession.Scopes,
Scopes: scopes,
Client: client,
CurrentStep: currentStep,
RequiredSteps: requiredSteps,