Skip to content

fix(coderd): render HTML error page for OIDC email validation failures#23059

Merged
angrycub merged 3 commits into
mainfrom
fix/oidc-email-error-page
Mar 16, 2026
Merged

fix(coderd): render HTML error page for OIDC email validation failures#23059
angrycub merged 3 commits into
mainfrom
fix/oidc-email-error-page

Conversation

@angrycub
Copy link
Copy Markdown
Contributor

Summary

When the email address returned from an OIDC provider doesn't match the configured allowed domain list (or isn't verified), users previously saw raw JSON dumped directly in the browser — an ugly and confusing experience during a browser-redirect flow.

This PR replaces those JSON responses with the same styled static HTML error page already used for group allow-list errors, signups-disabled, and wrong-login-type errors.

Changes

coderd/userauth.go

Replaced 3 httpapi.Write calls in userOIDC with site.RenderStaticErrorPage:

Error case Title shown
Email domain not in allowed list "Unauthorized email"
Malformed email (no @) with domain restrictions "Unauthorized email"
email_verified is false "Email not verified"

All render HTTP 403 with HideStatus: true and a "Back to login" action button.

coderd/userauth_test.go

  • Updated AssertResponse callbacks on existing table-driven tests (EmailNotVerified, NotInRequiredEmailDomain, EmailDomainForbiddenWithLeadingAt) to verify HTML Content-Type and page content.
  • Extended TestOIDCDomainErrorMessage to additionally assert HTML rendering.
  • Added new TestOIDCErrorPageRendering with 3 subtests covering all error scenarios, verifying: HTML doctype, expected title/description, "Back to login" link, and absence of JSON markers.

Replace raw JSON httpapi.Write responses with site.RenderStaticErrorPage
for three OIDC authentication error cases:

- Email address not from an authorized domain
- Malformed email (missing @ when domain restrictions are configured)
- Email address not verified by the OIDC provider

These errors occur during browser redirect flows, so users previously
saw ugly JSON in their browser. Now they see the same styled static
error page used by group allow-list and signups-disabled errors, with
a 'Back to login' action button.
@angrycub angrycub force-pushed the fix/oidc-email-error-page branch from d081153 to f33087a Compare March 15, 2026 01:04
@angrycub angrycub requested review from Copilot and johnstcn March 16, 2026 15:01
@angrycub angrycub force-pushed the fix/oidc-email-error-page branch from f33087a to fbc8fc1 Compare March 16, 2026 15:05
Comment thread coderd/userauth_test.go Outdated
Comment on lines +2132 to +2135
// TestOIDCErrorPageRendering verifies that OIDC authentication errors
// (unauthorized email domain, unverified email) render a user-friendly
// HTML error page instead of raw JSON.
func TestOIDCErrorPageRendering(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's roll these checks into the existing tests instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — removed TestOIDCErrorPageRendering and rolled the stronger assertions (doctype check, "Back to login" link, no JSON markers) into the existing TestUserOIDC table-driven callbacks and TestOIDCDomainErrorMessage subtests.

Remove standalone TestOIDCErrorPageRendering and roll its checks
(doctype, Back to login, no JSON markers) into the existing
TestUserOIDC and TestOIDCDomainErrorMessage assertions.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the OIDC browser login experience by rendering the existing styled static HTML error page (instead of raw JSON) when email validation fails during the redirect/callback flow.

Changes:

  • Switch OIDC email-domain and email_verified=false failures from httpapi.Write JSON responses to site.RenderStaticErrorPage (HTTP 403, hidden status, “Back to login” action).
  • Update existing OIDC tests to assert HTML Content-Type and key page text for these error cases.
  • Add a new focused test (TestOIDCErrorPageRendering) covering the main OIDC error scenarios and ensuring JSON markers aren’t present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
coderd/userauth.go Render static HTML error pages for OIDC email verification/domain failures.
coderd/userauth_test.go Update/add tests to verify HTML error rendering and content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread coderd/userauth.go
@angrycub angrycub force-pushed the fix/oidc-email-error-page branch from fbc8fc1 to 12231e9 Compare March 16, 2026 15:14
Copilot review noted a malformed logging statement. Updated to emit email as apparently intended.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@angrycub angrycub merged commit e94de0b into main Mar 16, 2026
22 checks passed
@angrycub angrycub deleted the fix/oidc-email-error-page branch March 16, 2026 15:57
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants