Skip to content

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

@marcoroth

Description

@marcoroth

Rule: html-disallow-inline-scripts

Description

Disallow the use of inline <script> tags and 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 <script> tags embedded directly in templates.
  • No event handler attributes (onclick, onmouseover, etc.).

Examples

✅ Good
<head>
  <%= javascript_include_tag "application" %>
</head>

<button class="btn btn-primary">Submit</button>
🚫 Bad
<head>
  <script>
    alert("Welcome!");
  </script>
</head>

<button onclick="alert('Clicked!')">Submit</button>

References

Inspired by @pushcx

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions