Skip to content

Commit

Permalink
fix: return InvalidArgument for OIDC empty state and code (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbh authored Nov 5, 2024
1 parent 6b4d111 commit 3bd93db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion core/authenticate/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ var (
ErrStrategyNotApplicable = errors.New("strategy not applicable")
ErrUnsupportedMethod = errors.New("unsupported authentication method")
ErrInvalidMailOTP = errors.New("invalid mail otp")
ErrMissingOIDCCode = errors.New("OIDC code is missing")
ErrInvalidOIDCState = errors.New("invalid auth state")
ErrFlowInvalid = errors.New("invalid flow or expired")
)

Expand Down Expand Up @@ -611,7 +613,12 @@ func (s Service) applyPasskey(ctx context.Context, request RegistrationFinishReq
func (s Service) applyOIDC(ctx context.Context, request RegistrationFinishRequest) (*RegistrationFinishResponse, error) {
// flow id is added in state params
if len(request.State) == 0 {
return nil, errors.New("invalid auth state")
return nil, ErrInvalidOIDCState
}

// flow id is added in state params
if len(request.Code) == 0 {
return nil, ErrMissingOIDCCode
}

// check for oidc flow via fetching oauth state, method parameter will not be set for oauth
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v1beta1/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (h Handler) AuthCallback(ctx context.Context, request *frontierv1beta1.Auth
StateConfig: request.GetStateOptions().AsMap(),
})
if err != nil {
if errors.Is(err, authenticate.ErrInvalidMailOTP) {
if errors.Is(err, authenticate.ErrInvalidMailOTP) || errors.Is(err, authenticate.ErrMissingOIDCCode) || errors.Is(err, authenticate.ErrInvalidOIDCState) {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
return nil, status.Error(codes.Internal, err.Error())
Expand Down

0 comments on commit 3bd93db

Please sign in to comment.