Skip to content

fix: preserve API_EXTERNAL_URL path when building confirmation links#2591

Open
tsushanth wants to merge 1 commit into
supabase:masterfrom
tsushanth:fix/external-url-path-preservation
Open

fix: preserve API_EXTERNAL_URL path when building confirmation links#2591
tsushanth wants to merge 1 commit into
supabase:masterfrom
tsushanth:fix/external-url-path-preservation

Conversation

@tsushanth

Copy link
Copy Markdown

Fixes #2518

When API_EXTERNAL_URL includes a path prefix (e.g. http://127.0.0.1:54321/auth/v1), Go's url.ResolveReference implements RFC 3986 §5.2 and replaces the entire base path with the reference path. Every confirmation and magic-link URL built in templatemailer.go uses externalURL.ResolveReference(path), so the /auth/v1 prefix is silently dropped and the link 404s.

The fix introduces resolveWithBasePath, a thin wrapper that prepends the base URL's path to the reference path rather than replacing it, then replaces all six call sites. The behavior is unchanged when API_EXTERNAL_URL has no path (the common case), because strings.TrimRight("", "/") is "".

Affected call sites: InviteMail, ConfirmationMail, EmailChangeMail, RecoveryMail, MagicLinkMail, GetEmailActionLink.

The existing URL test fixture is updated to reflect the correct (non-buggy) expectation, and a new case covering the Supabase CLI default (/auth/v1 base path) is added.

@tsushanth tsushanth requested a review from a team as a code owner June 25, 2026 00:04
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.

Mailer drops path component of API_EXTERNAL_URL when building confirmation URLs

1 participant