Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use html/template, not text/template #41

Closed
echlebek opened this issue Feb 12, 2020 · 1 comment
Closed

Use html/template, not text/template #41

echlebek opened this issue Feb 12, 2020 · 1 comment

Comments

@echlebek
Copy link
Contributor

We should be using the html/template package, not text/template, for working with templated HTML. The html/template package sanitizes its inputs.

This is a security issue; without html/template, malicious input can be injected into the email message.

See https://golang.org/pkg/html/template/

@hurrycaine
Copy link
Contributor

hurrycaine commented Mar 14, 2020

There is some benefit of using text/template, like controlling white space when the body (or subject) is plain text. I can see this being really helpful on the subject, where you could have complex conditionals but every square inch is important.

Example from the docs.

For instance, when executing the template whose source is

"{{23 -}} < {{- 45}}"
the generated output would be

"23<45"

This also could be a breaking change if someone used html and used {{23 -}}. In HTML all extra white space becomes one, so it really is not needed. However, it will fail if left in with this change.

echlebek added a commit that referenced this issue Mar 25, 2020
Fixes #41 Use html/template if email body is HTML

Otherwise, use text/template
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

No branches or pull requests

2 participants