fix(oauth-provider): allow localhost subdomains in isLocalhost function#8286
Conversation
This would allow a user to set a subdomain.localhost as a redirect uri for oauth. Currently it will not allow localhost subdomains witch are common in development
|
@sicarius97 is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
There was a problem hiding this comment.
Pull request overview
Expands the OAuth redirect URI URL validation to treat *.localhost hostnames as localhost, enabling common dev setups that use subdomain.localhost redirect URIs.
Changes:
- Update
isLocalhost()to allow hostnames ending with.localhostfor the HTTP-allowed localhost exception.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function isLocalhost(hostname: string): boolean { | ||
| return ( | ||
| hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" | ||
| hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname.endsWith(".localhost") |
There was a problem hiding this comment.
This change expands isLocalhost to allow *.localhost, but the existing SafeUrlSchema tests don't cover this new allowed case. Add a unit test that http://<subdomain>.localhost:<port>/... is accepted, to prevent regressions and ensure the intended behavior stays supported.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
ALso to fix lint error
…on (#8286) Co-authored-by: Alex Yang <himself65@outlook.com>
…on (#8286) Co-authored-by: Alex Yang <himself65@outlook.com>
This would allow a user to set a subdomain.localhost as a redirect uri for oauth. Currently it will not allow localhost subdomains which are common in some companies development practices. This is a very simple 1 line logic change.
Summary by cubic
Treat *.localhost as localhost in OAuth redirect URI validation so subdomain.localhost redirects (e.g., app.localhost) work in local development. Refactors isLocalhost in oauth-provider zod types for clarity; fixes lint.
Written for commit 4371c3f. Summary will update on new commits.