alert('pwned') This happens because: During HTML parsing...">

html/template: dynamic substrings in HTML tags or attributes can result in unsafe HTML output (original) (raw)

The following template:

<s{{.X}}>alert('pwned')

produces the following HTML output when executed with X = "cript":

This happens because:

In general, allowing dynamic substrings in HTML tags or attributes may confuse the parser and escaper, since the static and dynamic parts of the name are handled in different phases.

Suggested solution: disallow dynamic substrings in HTML tags or attributes completely.