Skip to content

fix(oauth-provider): allow localhost subdomains in isLocalhost function#8286

Merged
himself65 merged 4 commits intobetter-auth:canaryfrom
sicarius97:oauth-islocalhost-fix
Mar 2, 2026
Merged

fix(oauth-provider): allow localhost subdomains in isLocalhost function#8286
himself65 merged 4 commits intobetter-auth:canaryfrom
sicarius97:oauth-islocalhost-fix

Conversation

@sicarius97
Copy link
Copy Markdown
Contributor

@sicarius97 sicarius97 commented Mar 2, 2026

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.

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
Copilot AI review requested due to automatic review settings March 2, 2026 16:57
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 2, 2026

@sicarius97 is attempting to deploy a commit to the better-auth Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 2, 2026

Open in StackBlitz

@better-auth/api-key

npm i https://pkg.pr.new/@better-auth/api-key@8286

better-auth

npm i https://pkg.pr.new/better-auth@8286

auth

npm i https://pkg.pr.new/auth@8286

@better-auth/core

npm i https://pkg.pr.new/@better-auth/core@8286

@better-auth/drizzle-adapter

npm i https://pkg.pr.new/@better-auth/drizzle-adapter@8286

@better-auth/electron

npm i https://pkg.pr.new/@better-auth/electron@8286

@better-auth/expo

npm i https://pkg.pr.new/@better-auth/expo@8286

@better-auth/i18n

npm i https://pkg.pr.new/@better-auth/i18n@8286

@better-auth/kysely-adapter

npm i https://pkg.pr.new/@better-auth/kysely-adapter@8286

@better-auth/memory-adapter

npm i https://pkg.pr.new/@better-auth/memory-adapter@8286

@better-auth/mongo-adapter

npm i https://pkg.pr.new/@better-auth/mongo-adapter@8286

@better-auth/oauth-provider

npm i https://pkg.pr.new/@better-auth/oauth-provider@8286

@better-auth/passkey

npm i https://pkg.pr.new/@better-auth/passkey@8286

@better-auth/prisma-adapter

npm i https://pkg.pr.new/@better-auth/prisma-adapter@8286

@better-auth/redis-storage

npm i https://pkg.pr.new/@better-auth/redis-storage@8286

@better-auth/scim

npm i https://pkg.pr.new/@better-auth/scim@8286

@better-auth/sso

npm i https://pkg.pr.new/@better-auth/sso@8286

@better-auth/stripe

npm i https://pkg.pr.new/@better-auth/stripe@8286

@better-auth/telemetry

npm i https://pkg.pr.new/@better-auth/telemetry@8286

@better-auth/test-utils

npm i https://pkg.pr.new/@better-auth/test-utils@8286

commit: 5be5aaf

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

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 .localhost for 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")
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@himself65 himself65 changed the title Fix(oauth-provider): Allow localhost subdomains in isLocalhost function fix(oauth-provider): allow localhost subdomains in isLocalhost function Mar 2, 2026
@himself65 himself65 enabled auto-merge March 2, 2026 19:06
@himself65 himself65 added this pull request to the merge queue Mar 2, 2026
Merged via the queue into better-auth:canary with commit 9cc07e0 Mar 2, 2026
19 of 21 checks passed
himself65 added a commit that referenced this pull request Mar 3, 2026
…on (#8286)

Co-authored-by: Alex Yang <himself65@outlook.com>
himself65 added a commit that referenced this pull request Mar 3, 2026
…on (#8286)

Co-authored-by: Alex Yang <himself65@outlook.com>
@better-auth better-auth locked as resolved and limited conversation to collaborators Mar 31, 2026
@bytaesu bytaesu added the locked Locked conversations after being closed for 7 days label Mar 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked Locked conversations after being closed for 7 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants