Repository navigation
🔒 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 invalue,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&,",<and>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" onfocus="alert(1)">
-
Single-Quoted Values Are Escaped Too
Values wrapped in single quotes, the documented way to pass JSON for attributes likehx-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 malformedtitle=', now renders correctly astitle="'".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&is now escaped again and renders as&amp;. The most visible everyday change is URLs with query strings:attrs.Href: "/search?q=a&page=2"now renders ashref="/search?q=a&page=2", which browsers decode back to the original URL. Unlike text content, there is noRawequivalent for attributes, so every value goes through escaping.
No code changes are required unless you were escaping manually. All existing tests pass unchanged.