A value computed at run time is marked as safe HTML, JavaScript or URL content for html/template

tx0/go:unescaped-template-contentrecommendedwarningsecurity, cwe-79

What it finds

template.HTML(comment): html/template escapes every value it inserts, except values of its types HTML, JS, JSStr, URL, CSS, HTMLAttr and Srcset, which it trusts to be safe already. Converting text that comes from a request or a database turns the escaping off for it, so markup or script in it runs in the page.

The conversion must be to one of those types of html/template, resolved through the imports, and its operand must not be a constant string of the file.

From the rule's source, unescaped_template_content.rs.

Example from the rule's tests
package p import "html/template" const banner = "<b>hello</b>" func f(comment string) []template.HTML {	return []template.HTML{		template.HTML(comment),tx0 reports: template.HTML turns off escaping for a value computed at run time		template.HTML(banner),		template.HTML("<br>"),	}}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:unescaped-template-content" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:unescaped-template-content] reason="..."

tx0 explain tx0/go:unescaped-template-content shows the same in the terminal. Found a false positive? Report it.