Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return InvalidArgument for OIDC empty state and code #811

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading