Repository navigation
Description
The problem
<c-element> is the built-in tag that renders a plain HTML element whose tag name is decided at render time (c-is), or whose attributes come from a dict (c-bind). Since 0.7.0, a <c-element> with c-is or c-bind refuses an attribute whose name starts with on (such as onclick), and the names innerHTML, outerHTML and srcdoc. It refuses them even when the template author wrote them:
<c-element
c-is="tag"
onclick="save()"
>Save</c-element>
This raises ValueError. The aim is to refuse a handler that request data chose. A handler the template author wrote is safe, but this tag cannot tell the two apart, so it refuses both, as the 0.7.0 changelog says. Its workaround is a Vue @event in a component with js, or a plain element in a c-if branch. That leaves a template that needs a dynamic tag and a native handler with no direct way to write it.
Why it cannot tell
Two checks refuse these names. One is in _resolve_element_attrs (dynamic.py), the place every name reaches the element: a name written in the template, a c-bind mapping, <c-component c-is="element"> passing names on, and a direct Python call. By the time a name arrives there, the template-written names and the others are merged into one set of keyword arguments. The other check is at the component node that builds the element's inputs, where it refuses c-bind keys of this kind.
The template-written names and the c-bind names are still apart at that component node: a name written in the template comes from the tag's own attributes, and a name from c-bind comes from the mapping.
What we want
- Have the code that builds a component tag's inputs (the component node, in
nodes/__init__.py) pass the element the set of attribute names the template wrote, as an extra input. - In
_resolve_element_attrs, let anon*name through only when the set holds it. Refuse every other route as now. - Decide in the plan whether
innerHTML,outerHTMLandsrcdocwritten in the template follow the same rule.
Because this loosens a check that stops data from choosing browser behavior, it needs a written plan and the security pass that CLAUDE.md asks for before a change merges (Mechanism 7), with a reviewer who tries to put a name into the set from data.
Error modes to settle
- The set must never be filled from data. A
c-bindkey, a name<c-component c-is="element">passes on, and a Python call all stay outside it, even when the key looks like a name the template wrote. A test enforces this. - A template-written name with a value from data (
onclick="{{ x }}"). On a plain element a name the template wrote is never checked, whatever its value. Decide whether<c-element>does the same, and say so in the docs, or refuses a value that comes from data. - A hook can change the value of a handler the template wrote, but cannot add one. This is the rule for plain elements today.
- A name in the set on a tag the element refuses (such as
script) stays refused. The tag list is separate from the name rule.
Tests
Each side gets its own test:
- A template-written
<c-element c-is="button" onclick="...">renders. - The same name from
c-bind, from<c-component c-is="element">, and from a Python call raisesValueError. - A name that a hook adds raises.
Done when
- The tests above pass.
- The
<c-element>docs and the changelog describe the new rule, and the workaround text is gone from them. - A review record in
docs/security/reviews/says which routes were tried.
Activity