Skip to content

Version 0.37.0

Latest

Choose a tag to compare

@chasefleming chasefleming released this 24 Oct 20:32
· 1 commit to main since this release
c71e2b0

🔒 Security

🛡️ Attribute Value Escaping

  • Attribute Values Are Now Escaped
    Attribute values were previously written to the output verbatim. A value containing a double quote could terminate its attribute and inject new ones, so user-controlled data in value, href, title, placeholder, data-* or any other attribute was an XSS vector. Values are now escaped in the same way text content already was: &, ", < and > become &amp;, &quot;, &lt; and &gt; inside double-quoted values.

    elem.Input(attrs.Props{attrs.Value: `foo" onfocus="alert(1)`})
    // Before: <input value="foo" onfocus="alert(1)">
    // After:  <input value="foo&quot; onfocus=&quot;alert(1)">
  • Single-Quoted Values Are Escaped Too
    Values wrapped in single quotes, the documented way to pass JSON for attributes like hx-vals, keep their enclosing quotes and are escaped for that context: &, ', < and > are replaced while embedded double quotes are left as they are. A value like 'foo' onclick='alert(1)' can no longer break out of its attribute. A lone ' value, which used to render as the malformed title=', now renders correctly as title="'".

    Thanks to @whisk for reporting and fixing this.

⚠️ Behavior Change

  • Pass Attribute Values Unescaped
    If you were pre-escaping attribute values yourself, stop. A value that already contains entities such as &amp; is now escaped again and renders as &amp;amp;. The most visible everyday change is URLs with query strings: attrs.Href: "/search?q=a&page=2" now renders as href="/search?q=a&amp;page=2", which browsers decode back to the original URL. Unlike text content, there is no Raw equivalent for attributes, so every value goes through escaping.

No code changes are required unless you were escaping manually. All existing tests pass unchanged.