Skip to content

fix(events): refuse standard DOM event names in Dispatch and in the browser - #867

Merged
JuroOravec merged 3 commits into
mainfrom
events/dispatch-refuse-dom-names
Nov 24, 2026
Merged

JuroOravec merged 3 commits into
mainfrom
events/dispatch-refuse-dom-names

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

(Opus 5.5)

actions.Dispatch(name=...) now refuses the name of a standard DOM event, such as click, submit, input, change, keydown or focus, and names that start with vue:, vnode- or citry:. Citry's browser code refuses the same names before it fires the CustomEvent, so Citry.events.applyActions rejects them too. Custom names such as TaskRow:saved or order-saved are still accepted.

Closes #704

Why

An event action fires a bubbling CustomEvent at the component's first element. It reaches listeners on that element, its ancestors, document and window. A name such as click therefore runs the page's own listeners, including Vue @click handlers and @c-* bindings that call the server. When a handler takes the name from request data, the request picks which of those listeners run. The maintainer decided on #704 to refuse these names on the server and again in the browser.

The list and where it lives

  • One list. DOM_EVENT_NAMES in citry/_html_attribute_values.py, made by scripts/generate_html_attribute_values.py. It merges the HTML Standard's event handler index, Vue's Events type and names added by hand. The lint rules already read it. This PR adds 44 names browsers fire at document and window, or still fire without a current standard, for 175 in all. Examples: DOMContentLoaded, readystatechange, the webkit* animation events, search, mousewheel, the mutation events, gamepad and picture-in-picture events.
  • Browser copy. The generator writes a copy of the list into _vue/client.js between marker comments. --client-only copies the committed table without downloading anything. runtime.js is rebuilt from it.
  • Sync test. test_events_dispatch_names.py checks that the client.js block matches the Python table exactly, and that the prefix lists match.
  • Prefixes. citry:, vue: and vnode- live in RESERVED_EVENT_PREFIXES in actions.py, with a copy in client.js.
  • Guard against shrinking. REQUIRED_NAMES now also requires submit, input, change, keydown and message, so a refresh from the sources cannot quietly drop a common name.

Letter case

Both checks lowercase A-Z and then compare, so Click, KEYDOWN, DOMContentLoaded and Citry:ready are refused.

  • Why refuse every case. Browsers match event names exactly, so Click would not run a click listener. Some readers still fold case: HTML reads an onClick attribute as onclick, and Vue reads @Click on a component tag as click. No app needs a custom event that differs from a standard one only in case.
  • Why fold A-Z only. A name with a Unicode lookalike letter (Cyrillic с, the Kelvin sign) matches no standard listener. Python's str.lower and JavaScript's toLowerCase also disagree on some non-ASCII letters, so full Unicode folding would let the two checks drift apart.
  • Whitespace. Spaces around a name are not trimmed. A browser matches no listener for click.

Browser paths

One function, refuseReservedEventName, runs before any listener on every path:

  • applyPublicActionsWithoutApp: applyActions on a page with no mounted component, including wait: false and delayed actions.
  • The Events bridge's dispatchEvent: a server result for a mounted component. The check runs before the onEvent listeners as well as before the DOM event.
  • The bridge's dispatchEventGlobal: an untargeted event in an action list applied for a mounted component.

The protocol's reference validators (Python, JS and JSON Schema) still accept these names. The spec row says so: the refusal is Citry's own rule, applied on top of the wire format.

Versioning

Citry 1.2.x accepted these names, so this refuses input that used to work. It ships in 1.3.0 under the security exception in CLAUDE.md and docs/codebase.md "Breaking changes". Request data could choose which of the page's own listeners run, including @c-* bindings that send a server call. The changelog entry is marked Security. It lists the refused names, including common words such as close, toggle, error, load and message, and shows the fix: prefix the name with the component's name and listen for the new name.

The trust-boundaries doc had recorded an earlier plan to warn now and refuse in 2.0.0. The maintainer's decision on #704 replaces it, and the open-question row is removed.

Tests

  • Python. tests/test_events_dispatch_names.py (33 tests) covers representative refused names, case variants, prefixes, accepted custom names (including lookalikes and whitespace), the sync between the two copies, and the generator's marker writer. The focused events, lint, LSP and analysis suites pass (3254 tests).
  • JS. citry-client/test/dispatch-event-names.test.mjs (22 tests) runs against the shipped runtime.js: refused and accepted names, wait: false, and the runtime's own check when the protocol validator is bypassed. All 414 citry-client tests pass, including the canary that compares the rebuilt bundle.
  • End to end. test_the_browser_refuses_a_standard_event_name_on_a_mounted_component covers both bridge paths. Removing either browser check makes it fail; I confirmed this for each path.
  • Static checks. ruff and mypy pass, and mypy also passes with --platform linux. scripts/validate.py passes. In the local fast gate, pytest, the validators and the JS packages passed. The Rust phases and some pnpm phases failed only because this worktree has no ruff submodule and no node_modules for those packages; CI runs them.

Review

  • An independent reviewer did a technical pass, a security pass (Mechanism 7), the Mechanism 8 advisory check, a versioning check and a prose pass, then reviewed the follow-up fixes.
    • Security. No hole in any released version. The name was already documented as app code, never request data.
    • Gaps fixed in this PR. Browser event names missing from the list: the reviewer checked them in Chromium, Firefox and WebKit, and no on* handler outside the list remains. The browser test also did not reach either bridge path; the end-to-end test above now covers both.
  • docs-cold-reader read the changed docs as a first-time reader. Its findings are folded in.

Left for the maintainer

  1. Mechanism 7 list. Should CLAUDE.md's Mechanism 7 list name "event names" (the CustomEvent name of an Events event action) as a place where a value reaches the browser? I did not edit CLAUDE.md.
  2. Generated table. The DOM_EVENT_NAMES line was rewritten in the generator's exact format without downloading the sources, which this environment cannot reach. The module header still says it was generated on 2026-10-21. Run the generator online before the release to refresh all tables together.

🤖 Generated with Claude Code

JuroOravec and others added 3 commits November 24, 2026 19:46
…rowser

actions.Dispatch now raises ValueError for a standard DOM event name such
as click or submit, in any ASCII letter case, and for a name starting with
vue: or vnode- (citry: was already refused). The browser runtime refuses
the same names before it fires the CustomEvent, on every path. Its list is
a copy of DOM_EVENT_NAMES that scripts/generate_html_attribute_values.py
writes into _vue/client.js, and a test checks the two match.

Closes #704

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add legacy, prefixed and Window/Document event names that browsers still
fire (webkitAnimationEnd, search, mousewheel, the mutation events, and
others) to DOM_EVENT_NAMES, require the common ones in the generator,
state letter-case folding and the fix in both error messages, add an
end-to-end test for the mounted-component path in the browser, and bring
the docs, the spec row and the writing guide's quoted message in line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sult

The end-to-end test now sends an action list aimed at the mounted
component with an untargeted standard name after it, which reaches the
Events bridge's page-wide dispatch. Also refuse Chromium's installresult
and tidy the wording the reviewer flagged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit b565dbc into main Nov 24, 2026
34 checks passed
@JuroOravec
JuroOravec deleted the events/dispatch-refuse-dom-names branch November 24, 2026 20:08
JuroOravec added a commit that referenced this pull request Nov 24, 2026
* build: refresh the HTML attribute tables from the live standards

Run scripts/generate_html_attribute_values.py with network access so every
table and the module header's generation date match the current sources. The
only table change is the HTML Standard's new `switch` attribute of `input`, a
boolean attribute. DOM_EVENT_NAMES is unchanged: the 44 names added in #867
live in SUPPLEMENTAL_EVENT_NAMES in the script, and a full run keeps all 175.

Add tests for `switch` and for the script's hand-added event names, and
document the script's copy of the event names in client.js.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* docs(changelog): note the new switch findings in citry check

Both rules that read the new `switch` entry are errors by default, so a
template with `switch="false"` or a typo of `switch` now fails `citry check`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
JuroOravec added a commit that referenced this pull request Nov 24, 2026
#871 (#878)

Records the Mechanism 7 security reviews of six merged Events changes, in
the form docs/security/reviews/README.md describes. Each record is built
from the pull request description, the merged diff and its tests; where a
description does not record something the template asks for, the record
says so.

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decide whether Dispatch refuses names of standard DOM events

1 participant