#18
Fix Gmail OAuth redirect origin
Summary
- build the Gmail completion redirect from the configured public
BETTER_AUTH_URL - avoid leaking Railway's internal container origin through
request.url - cover connected, error, and unauthorized completion destinations
- document how to diagnose an internal-host OAuth redirect
Root cause
Railway received the callback on redakt-staging.up.railway.app, but Next exposed the upstream container URL as request.url. The completion route used that internal URL as the base for its final redirect.
Validation
pnpm test(63 tests)- focused ESLint
pnpm exec tsc --noEmitpnpm buildgit diff --check
Activity
4mikeyreviewed3mo ago
ee2af65 into main3mo ago
Reviewed the full diff (
app/api/mail/accounts/google/complete/route.ts,lib/google/oauth.ts,lib/google/oauth.test.mjs,docs/gmail.md) plus the dependencies it touches (lib/env.ts:getAppUrl,lib/mail/routes.ts:mailAccountsHref,lib/google/mail-accounts.ts:completeGoogleMailAccounts).Verification
connected,error,unauthorized) throughgmailCompletionRedirectUrlagainst the new unit tests inoauth.test.mjs— the produced URLs match exactly (/mail/settings/account?connected=1,?error=google,/?google=unauthorized).getAppUrl()(i.e.BETTER_AUTH_URL), sorequest.url— which exposed Railway's internal container origin — is no longer read anywhere in this handler. This is a real fix for the stated root cause; the base URL is server-configured, not derived from user input, so there's no open-redirect regression either.GET()dropping the unusedrequest: Requestparameter is safe — nothing else in the removed code read query params or headers off it.Non-blocking note
getAppUrl()silently falls back tohttp://localhost:3000ifBETTER_AUTH_URLis unset (lib/env.ts:38), so a missing/misconfigured env var in a new environment would reproduce a similar-looking wrong-origin redirect (pointing at localhost) with no error surfaced. Pre-existing behavior, not introduced by this PR, but worth a startup assertion at some point since this route now depends on it entirely for correctness.No blocking correctness, security, or test-coverage issues found in this pass.