Skip to content

fix: oidc server error to http status mapping#865

Merged
muhlemmer merged 6 commits intomainfrom
fix-server-error-http-status-mapping
Apr 9, 2026
Merged

fix: oidc server error to http status mapping#865
muhlemmer merged 6 commits intomainfrom
fix-server-error-http-status-mapping

Conversation

@grvijayan
Copy link
Copy Markdown
Contributor

@grvijayan grvijayan commented Apr 1, 2026

This PR maps OIDC server errors to HTTP Status 500

Additional changes: Map verifier errors to appropriate OIDC errors to prevent mapping the generic verifier errors to OIDC server error by default.

Closes #852

@muhlemmer muhlemmer self-requested a review April 2, 2026 16:44
Comment thread pkg/oidc/error.go Outdated
Comment on lines +225 to +257
func mapVerifierError(err error, description string) error {
oidcErr := new(Error)
if ok := errors.As(err, &oidcErr); ok {
return err
}
switch {
case errors.Is(err, ErrParse):
err = ErrInvalidRequest().WithParent(err).WithDescription("%s", description)
case errors.Is(err, ErrIssuerInvalid),
errors.Is(err, ErrSubjectMissing),
errors.Is(err, ErrAudience),
errors.Is(err, ErrAzpMissing),
errors.Is(err, ErrAzpInvalid),
errors.Is(err, ErrSignatureMissing),
errors.Is(err, ErrSignatureMultiple),
errors.Is(err, ErrSignatureUnsupportedAlg),
errors.Is(err, ErrSignatureInvalidPayload),
errors.Is(err, ErrSignatureInvalid),
errors.Is(err, ErrExpired),
errors.Is(err, ErrIatMissing),
errors.Is(err, ErrIatInFuture),
errors.Is(err, ErrIatToOld),
errors.Is(err, ErrNonceInvalid),
errors.Is(err, ErrAcrInvalid),
errors.Is(err, ErrAuthTimeNotPresent),
errors.Is(err, ErrAuthTimeToOld),
errors.Is(err, ErrAtHash):
err = ErrInvalidGrant().WithParent(err).WithDescription("%s", description)
case errors.Is(err, ErrDiscoveryFailed):
err = ErrServerError().WithParent(err).WithDescription("%s", description)
}
return err
}
Copy link
Copy Markdown
Collaborator

@muhlemmer muhlemmer Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can inline this code into DefaultToServerError. There's another errors.As asserting the type Error type there, we can remove that.

I think we also need to add default to the case switch which still creates a server error as default.

@grvijayan grvijayan marked this pull request as ready for review April 9, 2026 07:00
@grvijayan grvijayan requested a review from muhlemmer April 9, 2026 07:01
Copy link
Copy Markdown
Collaborator

@muhlemmer muhlemmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks!

@muhlemmer muhlemmer merged commit d118dd7 into main Apr 9, 2026
5 checks passed
@muhlemmer muhlemmer deleted the fix-server-error-http-status-mapping branch April 9, 2026 07:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

🎉 This PR is included in version 3.47.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@aymkhalil
Copy link
Copy Markdown

thank you 🙏 - we've consumed the change and it working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RequestError always maps server_error to HTTP 400

3 participants