TL;DR
The :html=\"expr\" reactive binding emits client-side code that calls el.innerHTML = <expr-result> with no sanitization. This is the framework's analogue of Vue's v-html / React's dangerouslySetInnerHTML — opt-in raw-HTML escape hatch — but unlike those frameworks, there's no documented warning, no lint rule, and no "escape by default; opt out via :html-unsafe" mode for the common case.
Today's code path in packages/stx/src/reactive-bindings.ts:237-247:
else if (attribute === 'html') {
// html binding - update innerHTML
code += ` (function() {
var el = document.getElementById('${elementId}');
if (el) {
try {
el.innerHTML = ${evalExpr};
}
catch (e) { console.error('Binding error:', e); }
}
})();
`
}evalExpr is whatever the user wrote in their template (store.commentBody, post.html, …). If any of those ever hold attacker-controlled HTML — comment fields, search-result snippets, JSON from a third-party API — that markup runs in the page's origin.
Why this isn't strictly a bug today
It's an opt-in API. Developers writing :html=\"foo\" are explicitly choosing raw HTML, the same way they would with v-html. The risk is when this becomes a habit and an unrelated change starts pushing user input into the bound store, with no lint or runtime guard to catch it.
Proposed improvements
Pick any subset:
- Doc-level: prominent warning in the directive docs that
:html=is the framework'sv-htmlequivalent, only safe with trusted content. Currently the directive isn't documented as such. - Sanitizer hook: stx already ships
@stacksjs/sanitizer. Add an opt-in:html.safe=\"foo\"modifier that pipes through the sanitizer before writing. The bare:html=keeps current behavior. - Strict-mode warning: when stx strict mode is on, warn on
:html=usage at compile time (similar to the existing strict-mode hints fordocument.querySelectoretc.). - Build-time AST check: a pre-existing project lint rule could refuse
:html=\"<storeName>.<field>\"patterns that touch untrusted store data, by inspecting the source store's declared shape.
Found during a deep-scan audit. Not a bug, but the framework's only XSS-shaped escape hatch shouldn't be undocumented and unguarded.
🤖 Filed via Claude Code