Skip to content

/oauth_login and /oauth_callback ignore a client's registered redirect_uris (social login fails with "invalid redirect uri" for clients on other origins) #855

Closed

Description

@kurnias

Version: 2.4.4 (image digest sha256:d1ce7574a75d409f83ef611d7fab4846da64f3d30595f7d5a2bd0e083a97e28d; main still has the same code at the time of writing)

Describe the bug

Social login (/oauth_login/:provider) does not honour the registered redirect_uris of a client. It only accepts a redirectURL whose origin is listed in --allowed-origins. So for a client registered through /oauth/register (RFC 7591), whose callback is on its own domain, /authorize, /app, the token endpoint and password login all work, but the "Continue with GitHub/Google" buttons on the hosted login page end in:

HTTP 400  {"error":"invalid redirect uri"}

The only workaround is to add every app's origin to the instance-wide --allowed-origins and restart the server. That list is also used for CORS, the GraphQL CSRF check, and the redirect_uri validation of password reset, magic link, sign-up, logout, SSO and SAML, so each new app widens all of those, and a new client can no longer be registered at run time and be complete.

Where it comes from (tag 2.4.4)

  • internal/http_handlers/oauth_login.go:47 validates with validators.IsValidRedirectURI(redirectURI, h.Config.AllowedOrigins, hostname). The handler never reads client_id and never calls checkClientRedirectURI.
  • internal/http_handlers/oauth_callback.go:120 repeats the same origin-only check on statePayload.RedirectURI, so fixing only the login side would not be enough.
  • checkClientRedirectURI (client_redirect.go), the function that applies a client's registered redirect_uris (and --redirect-uris for the deployment's own client), is called only from authorize.go:178, app.go:60 and verify_email.go:53. The comment on it describes exactly this gap for /app ("When /app applied a different (AllowedOrigins-only) rule, every client whose registered redirect_uri was not also an allowed origin passed the first check and failed the second"). /oauth_login has the same shape of problem.
  • The login page buttons (@authorizerdev/authorizer-react 2.2.0, bundled in web/app/build) call window.location.href = <authorizerURL>/oauth_login/<provider>?state=..&scope=..&redirectURL=<redirect_uri>&redirect_uri=<redirect_uri>&isOrgDiscoveryEnabled=false. client_id is not sent, even when the page was opened with ?client_id=... (observed in headless Chromium, for both /app/?client_id=..&redirect_uri=.. and the redirect that /authorize issues).

Steps To Reproduce

Any 2.4.4 instance with a GitHub or Google client configured (fake credentials are enough, validation happens before the redirect to the provider), --allowed-origins=https://auth.example.com, --enable-dynamic-client-registration:

# 1. register a client whose callback is on another domain
curl -s https://auth.example.com/oauth/register -H 'Content-Type: application/json' -d '{
  "client_name":"app","redirect_uris":["https://app.example.org/auth/callback"],
  "grant_types":["authorization_code","refresh_token"],"response_types":["code"],
  "token_endpoint_auth_method":"none"}'            # -> {"client_id":"<id>", ...}

# 2. /authorize and /app accept that callback (the login page renders), but the social login does not:
curl -s -o /dev/null -w '%{http_code}\n' --get https://auth.example.com/oauth_login/github \
  --data-urlencode state=x --data-urlencode 'redirectURL=https://app.example.org/auth/callback'
# 400   (with or without an extra client_id=<id> parameter)

curl -s -o /dev/null -w '%{http_code}\n' --get https://auth.example.com/oauth_login/github \
  --data-urlencode state=x --data-urlencode 'redirectURL=https://auth.example.com/anything/at/all'
# 307   (any path on an allowed origin passes)

Measured results (same on a throwaway instance with --redirect-uris=https://app.example.org/auth/callback --client-id <deployment client>): the registered callback stays at 400; --redirect-uris has no effect on /oauth_login, because it is consulted only through checkClientRedirectURI. After adding https://app.example.org to --allowed-origins, the callback and every other path on that origin return 307.

Expected behavior

When the request identifies a client, /oauth_login (and the matching check in /oauth_callback) should validate redirect_uri against that client's registered redirect_uris, exactly like /authorize and /app already do. Without a client_id the current behaviour stays as it is, so existing deployments are unaffected.

Proposed change (happy to send a PR if you agree with the direction)

  1. authorizer-react: include client_id (when the page has one) in the query of the social login buttons.
  2. OAuthLoginHandler: read client_id; if present, use h.checkClientRedirectURI(ctx, clientID, redirectURI, hostname) instead of IsValidRedirectURI (fail closed on errClientUnavailable, as /authorize does); otherwise keep today's origin check.
  3. oauthStatePayload: store the client_id, and make /oauth_callback re-validate RedirectURI with the same function and that client, so both ends use the same rule.
  4. Tests next to app_redirect_uri_test.go / authorize_redirect_uri_test.go: registered callback accepted, unregistered path on the same origin refused for a client with registered URIs, no client_id unchanged.

Additional context

  • Side observation while reading validators/url.go: origin matching ignores the scheme (http://auth.example.com/x passes for https://auth.example.com) and is case-sensitive on the host. Probably intended, mentioned only in case it is not.
  • Related: the CHANGELOG entry for --redirect-uris and the /verify_email fix (GHSA-44vr-f829-xfch) already move other flows to exact, per-client matching; this would bring social login in line.
  • We run Authorizer as a shared identity service for several apps, each registered as its own dynamic client. For now we hide the social buttons for clients on other origins at our reverse proxy and accept email + password there.

Activity

  1. lakhansamani commented on Nov 17, 2026

    @lakhansamani
    Contributor

    Thank you @kurnias for this report. It was precise and easy to reproduce, and it led to a better fix than the obvious one.

    This is fixed and released in Authorizer 2.4.6, together with @authorizerdev/authorizer-react 2.2.1, which the hosted login page in 2.4.6 already bundles.

    What changed: instead of teaching /oauth_login to accept a client's registered redirect_uri, social login now resumes the original authorization request. That's the same path password login takes, and how Auth0 and others treat social connections:

    1. While /authorize is waiting for a sign-in, the login page sends its own /app URL to /oauth_login/<provider>, not the client's callback.
    2. The provider returns to /oauth_callback/<provider>. The callback signs the user in and goes back to that /app URL, with no code and nothing appended.
    3. /app replays the request to /authorize. That checks the client's registered redirect URIs, shows the consent screen if the client needs it, binds PKCE, and sends the code.

    Why it's done this way: simply accepting the client's callback at /oauth_login would have let a self-registered (DCR) client get a code through social login without the consent screen, because that gate lives in /authorize. Going back through /authorize fixes your case and closes that gap at the same time.

    What this means for your setup:

    • A client whose callback is on another origin now completes social login, with no need to list its origin in --allowed-origins.
    • If you added client origins to --allowed-origins as a workaround, you can remove them after upgrading. That list also drives CORS, the CSRF check and email-link redirects for every client.
    • The client's nonce comes back unchanged in the ID token.

    References:

    Tests: a new end-to-end test drives exactly this scenario in a real browser: a client outside --allowed-origins completes GitHub login, gets consent first, and redeems the code. That run also found that the login page is actually served at /app/, which every unit test had missed.

    Your two side notes: you also mentioned that origin matching ignores the scheme and is case-sensitive on the host. Those weren't part of this change. If they matter to you, please open a separate issue so they get looked at properly.

    Thanks again! 🙏

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions