Skip to content

fix: strip inline event handlers from sub-app HTML - #106

Merged
oto-macenauer-absa merged 1 commit into
masterfrom
fix/strip-inline-event-handlers
Sep 24, 2026
Merged

oto-macenauer-absa merged 1 commit into
masterfrom
fix/strip-inline-event-handlers

Conversation

@oto-macenauer-absa

Copy link
Copy Markdown
Collaborator

Closes #67.

script-src 'self' blocks onclick="…" exactly like an inline <script>, so an on* handler that survives the build is dead in production — and live under astro dev/preview, where the docs-example fixture's theme toggle re-added dark to a light-only knowledge base.

Of the two policies in the issue this takes strip: it is what production already does, made true everywhere. Hoisting handlers into listener files needs a stable element handle per attribute and preserves behaviour nobody should depend on — the checker already warns (KB-HTML-005).

Changes

  • transformSubAppHtml() drops every on* attribute (template content included); the element and its other attributes stay.
  • build-integrity.spec.js: no on* attribute anywhere in dist/, walked with parse5 so a handler quoted in prose is not flagged; the fixture's #theme-toggle is present without its handler (proves the strip ran on a real one).
  • transform.spec.js: stripping across head/body/template, bare on untouched, prose untouched.
  • contract/HEADLESS_RULES.md: new "Required: scripts as files" section + checklist item; RULES.md KB-HTML-005 says the handler is stripped.

The vendored fixture keeps its toggle: it is now the evidence that stripping works.

Verification

npm test: 402 passed.

🤖 Generated with Claude Code

script-src 'self' blocks onclick="…" exactly like an inline <script>, so a
handler that survives the build is dead in production. Where no CSP is
served (astro dev/preview) it runs, and the docs-example fixture's theme
toggle re-added `dark` there. transformSubAppHtml() now drops every on*
attribute; the element stays.

build-integrity asserts no on* attribute anywhere in dist/ (walked as a
parsed tree, so prose is not flagged) and that the fixture's toggle lost
its handler. HEADLESS_RULES.md gains a "scripts as files" section.

Closes #67

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@oto-macenauer-absa
oto-macenauer-absa merged commit 8c0a3aa into master Sep 24, 2026
8 checks passed
@oto-macenauer-absa
oto-macenauer-absa deleted the fix/strip-inline-event-handlers branch September 24, 2026 15:17
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.

Inline event handlers in sub-app HTML survive the build: dead under CSP, and a dark-mode leak without it

1 participant