Skip to content

fix: read template body from local file path when configured#2592

Open
tsushanth wants to merge 1 commit into
supabase:masterfrom
tsushanth:fix/template-local-file-path
Open

fix: read template body from local file path when configured#2592
tsushanth wants to merge 1 commit into
supabase:masterfrom
tsushanth:fix/template-local-file-path

Conversation

@tsushanth

Copy link
Copy Markdown

When GOTRUE_MAILER_TEMPLATES_* is set to a local file path such as
/etc/gotrue/templates/confirmation.html, the template loader was prepending
SiteURL and issuing an HTTP GET. Because /etc/gotrue/templates/confirmation.html
is not a valid URL path relative to the site, the GET would silently fail or
return the site's root HTML, causing outgoing emails to contain the rendered
HTML of the application rather than the intended template.

Root cause

loadEntryBody in internal/mailer/templatemailer/template.go checked only for
an http prefix to decide whether to fetch or prepend. Absolute paths, relative
paths (./), and file:// URIs all fell through to the SiteURL-prepend branch.

Fix

Add a path-vs-URL check before the fetch. Values starting with /, ./, or
file:// are read directly from disk with os.ReadFile. The file:// scheme is
stripped before the read so the path is passed verbatim to the OS. Only values
starting with http (or lacking any recognised scheme) continue through the
existing HTTP fetch path.

No existing tests are broken by this change. The default-template fallback and
the SiteURL-relative-fragment behavior are unchanged.

Fixes #2589

When GOTRUE_MAILER_TEMPLATES_* is set to a local file path (absolute path,
relative path, or file:// URI), the template loader was prepending SiteURL and
issuing an HTTP GET, which silently fetched the site's HTML page instead of the
intended template file.

Add a path-vs-URL check in loadEntryBody: values starting with '/', './', or
'file://' are read directly from disk with os.ReadFile. Only values that begin
with 'http' (or lack a recognized prefix) are handled via the existing HTTP
fetch path. The silent SiteURL-prepend fallback is preserved for relative URL
fragments as before.

Fixes supabase#2589
@tsushanth tsushanth requested a review from a team as a code owner June 25, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant