Skip to content

Latest commit

 

History

History
60 lines (39 loc) · 1.34 KB

File metadata and controls

60 lines (39 loc) · 1.34 KB

Linter Rule: Disallow ERB output in attribute position

Rule: erb-no-output-in-attribute-position

Description

ERB output tags (<%= %> or <%== %>) are not allowed in attribute position. Use ERB control flow (<% %>) with static attribute names instead.

Rationale

ERB output tags in attribute positions (e.g., <div <%= attributes %>>) allow arbitrary attribute injection at runtime. An attacker could inject event handler attributes like onmouseover or onfocus to execute JavaScript.

For example, a common pattern like:

<div <%= "hidden" if index != 0 %>>...</div>

should be rewritten to use control flow with static attributes:

<div <% if index != 0 %> hidden <% end %>>...</div>

This ensures attribute names are always statically defined and prevents arbitrary attribute injection.

Examples

Good

<div class="<%= css_class %>"></div>
<input value="<%= user.name %>">
<div <% if active? %> class="active" <% end %>></div>

Bad

<div <%= data_attributes %>></div>
<div <%== raw_attributes %>></div>
<div <%= first_attrs %> <%= second_attrs %>></div>

References