Skip to content

fix(security): restrict OAuth redirect_uri localhost bypass to local mode#4121

Open
0xcucumbersalad wants to merge 1 commit into
mainfrom
fix/oauth-redirect-localhost-bypass
Open

fix(security): restrict OAuth redirect_uri localhost bypass to local mode#4121
0xcucumbersalad wants to merge 1 commit into
mainfrom
fix/oauth-redirect-localhost-bypass

Conversation

@0xcucumbersalad

@0xcucumbersalad 0xcucumbersalad commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

The OAuth authorize endpoint at app.ts:425-428 allowed redirect_uri to any localhost URL regardless of environment:

const isAllowed =
  redirectUrl.origin === allowedOriginObj.origin ||
  redirectUrl.hostname === "localhost";  // ← always allowed, even in production

In production (cloud/container deployments), an attacker could set redirect_uri=http://localhost:8080/steal and intercept OAuth authorization codes if they can bind that port — possible on shared hosts, cloud VMs, or via browser extensions.

Fix

Gate the localhost exception behind localMode:

- redirectUrl.hostname === "localhost";
+ (getSettings().localMode && redirectUrl.hostname === "localhost");

Production only allows redirect_uri matching the configured baseUrl origin. Local dev (bun run dev / --local-mode) continues to allow localhost.

Test plan

  • bun run fmt — passes
  • bun run lint — passes (0 errors)
  • Verify OAuth flow works in production with redirect_uri matching baseUrl
  • Verify redirect_uri=http://localhost:8080/steal is rejected in production
  • Verify localhost redirect_uri still works in local mode

🤖 Generated with Claude Code


Summary by cubic

Restricts OAuth redirect_uri localhost allowance to local mode to close a production security gap. Prevents leaking authorization codes via http://localhost/... in cloud or container deployments.

  • Bug Fixes
    • Gate localhost redirects behind getSettings().localMode; production now requires origin to match baseUrl.
    • Updated validation in apps/mesh/src/api/app.ts and added clear comments on the risk and behavior.

Written for commit 798c8f1. Summary will update on new commits.

Review in cubic

…mode

The OAuth authorize endpoint allowed redirect_uri to any localhost URL
regardless of environment. In production (cloud/container deployments),
an attacker could set redirect_uri=http://localhost:8080/steal and
intercept OAuth authorization codes if they can bind that port on the
same host (shared environments, cloud VMs, browser extensions).

Gate the localhost exception behind localMode so it only applies during
development (bun run dev / --local-mode). Production deployments only
allow redirect_uri matching the configured baseUrl origin.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant