Skip to content

Linter: Implement html-no-event-handlers and html-no-script-elements rules#1536

Open
markokajzer wants to merge 2 commits intomarcoroth:mainfrom
markokajzer:marko/html-disallow-inline-scripts
Open

Linter: Implement html-no-event-handlers and html-no-script-elements rules#1536
markokajzer wants to merge 2 commits intomarcoroth:mainfrom
markokajzer:marko/html-disallow-inline-scripts

Conversation

@markokajzer
Copy link
Copy Markdown
Contributor

@markokajzer markokajzer commented Mar 29, 2026

closes #161


Rule: html-no-event-handlers

Description

Disallow the use of inline JavaScript event handler attributes (e.g. onclick, onload) in HTML templates.

Rationale

Inline JavaScript poses a significant security risk and is incompatible with strict Content Security Policy (CSP) configurations (script-src 'self').

All JavaScript should be included via external assets to support strong CSP policies that prevent cross-site scripting (XSS) attacks.

This rule enforces:

  • No event handler attributes (onclick, onmouseover, etc.) on HTML elements.
  • No event handler attributes on ActionView tag helpers (e.g. <%= tag.button onclick: "..." %>).

Rule: html-no-script-elements

Description

Disallow the use of inline <script> tags in HTML templates.

Rationale

Inline JavaScript poses a significant security risk and is incompatible with strict Content Security Policy (CSP) configurations (script-src 'self').

All JavaScript should be included via external assets to support strong CSP policies that prevent cross-site scripting (XSS) attacks.

This rule enforces:

  • No <script> tags embedded directly in templates.

@github-actions github-actions bot added documentation Improvements or additions to documentation linter typescript linter-rule labels Mar 29, 2026
@markokajzer markokajzer force-pushed the marko/html-disallow-inline-scripts branch from e037569 to 14743fe Compare March 29, 2026 22:34
@markokajzer markokajzer changed the title Linter: Implement html-disallow-inline-scripts rule Linter: Implement erb-disallow-inline-scripts rule Mar 29, 2026
@markokajzer markokajzer force-pushed the marko/html-disallow-inline-scripts branch 3 times, most recently from 5cd0512 to ab527ae Compare March 30, 2026 00:30
Copy link
Copy Markdown
Owner

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @markokajzer!

I think we want to keep the two rules separate so that the erb-no-javascript-tag-helper rule is strictly about avoid the javascript_tag Action View helper (should probably be renamed to actionview-no-javascript-tag-helper later).

And this rule should probably be just about inline script handler, for catching all the on* attributes. Both on the regular HTML element and on the ActionView tag helpers, like <%= tag.button onclick: "alert('hello')" %>. And we probably want to rename the rule to have a html-* prefix.

And then finally, we probably also want a third independent one that catches inline <script> HTML elements, either in the body or head.

@markokajzer markokajzer force-pushed the marko/html-disallow-inline-scripts branch from ab527ae to 8abbcf4 Compare March 30, 2026 21:30
@markokajzer markokajzer changed the title Linter: Implement erb-disallow-inline-scripts rule Linter: Implement html-no-event-handlers and html-no-script-elements rules Mar 30, 2026
@markokajzer
Copy link
Copy Markdown
Contributor Author

markokajzer commented Mar 30, 2026

changes:

  1. restored erb-no-javascript-tag-helper
  2. split out html-no-event-handlers
  3. split out html-no-script-elements
  4. both scan for action view helpers
  5. added some additional specs with more edge cases

i can separate into two PRs 👍

gonna leave the rename to #1359, so noop for now

@markokajzer markokajzer marked this pull request as ready for review March 30, 2026 21:34
@markokajzer markokajzer force-pushed the marko/html-disallow-inline-scripts branch from 8abbcf4 to 9ccc034 Compare March 30, 2026 21:38
@markokajzer markokajzer requested a review from marcoroth March 30, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation linter linter-rule typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter Rule: Disallow inline <script> tags and event handler attributes

2 participants