sanitizer-allows-style

A sanitizer configured to keep style or class in the HTML it lets through.

Group
Code
Runs
Runs under ur scan: ur scan --rule sanitizer-allows-style
Level
warning
Reads
Every file
Fix
None: whether the HTML is a user's is the caller's to know

Why

An HTML sanitizer such as DOMPurify removes scripts, but what its configuration allows stays. style attributes, <style> elements, and class attributes that name the page's own styles let whoever wrote the HTML place and size their own elements over the page, such as a login form or a link that looks like a button, which is HTML injection even with no script. Leave style and class out of ALLOWED_ATTR and ADD_ATTR, and style out of ALLOWED_TAGS and ADD_TAGS, for HTML a user can write.

The fix, as Ur suggests it: take style and class out of the allowed attributes.

For agents

Keep style and class out of a sanitizer's ALLOWED_ATTR and ADD_ATTR, and style out of its ALLOWED_TAGS and ADD_TAGS, for HTML a user can write.

Example

app/markdown.js
export const markdownConfig = {
  ALLOWED_TAGS: ['a', 'p', 'img'],
  ALLOWED_ATTR: ['class', 'style', 'href', 'src'],
};
What Ur prints
$ ur scan --rule sanitizer-allows-style
warning[sanitizer-allows-style]: `ALLOWED_ATTR` keeps `class` and `style` in sanitized HTML
  --> ./app/markdown.js:3:3 `ALLOWED_ATTR: ['class', 'style', 'href', 'src']`
  = hint: take `style` and `class` out of the allowed attributes
  = see: CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/79.html
scanned 1 file (no framework recognized)
  sanitizer-allows-style: 1 high, 0 medium
1 finding and 0 of medium confidence

Try it in the playground →

Source

CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), MITRE (2024-11-19).