fix: read template body from local file path when configured#2592
Open
tsushanth wants to merge 1 commit into
Open
fix: read template body from local file path when configured#2592tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
GOTRUE_MAILER_TEMPLATES_*is set to a local file path such as/etc/gotrue/templates/confirmation.html, the template loader was prependingSiteURLand issuing an HTTP GET. Because/etc/gotrue/templates/confirmation.htmlis 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
loadEntryBodyininternal/mailer/templatemailer/template.gochecked only foran
httpprefix to decide whether to fetch or prepend. Absolute paths, relativepaths (
./), andfile://URIs all fell through to the SiteURL-prepend branch.Fix
Add a path-vs-URL check before the fetch. Values starting with
/,./, orfile://are read directly from disk withos.ReadFile. Thefile://scheme isstripped before the read so the path is passed verbatim to the OS. Only values
starting with
http(or lacking any recognised scheme) continue through theexisting 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