Am I affected?

type your html_sanitize_ex version to check

Description

Inefficient Algorithmic Complexity vulnerability in the traversal engine in rrrene html_sanitize_ex allows an unauthenticated remote attacker to exhaust server CPU and memory via a flat run of sibling elements in sanitized HTML. The list clause of HtmlSanitizeEx.Traverser.traverse/2 recurses on the tail of a sibling list and then evaluates List.flatten([head] ++ tail) over the already flattened result, so every one of n siblings copies and re-walks the entire remaining tail. The flattening is only needed for the rare case where scrub returns several replacement nodes for one node, but the cost is paid across the whole tail at every step, making traversal quadratic in sibling count.

The traverser sits on every public entry point, so no particular scrubber or configuration is required and the payload needs only allowed tags. A 160 KB body of 20,000 sibling elements occupies a scheduler for roughly 1.7 seconds, and the cost grows faster than the body does.

This issue affects html_sanitize_ex: from 0.3.1 before 1.5.3.

Weaknesses & attack patterns

Weakness

CWE-407 · Inefficient Algorithmic Complexity in catalog → MITRE ↗

Attack patterns

CAPEC-130 · Excessive Allocation MITRE ↗

Affected — Hex / html_sanitize_ex Hex.pm ↗ Repository ↗

0.3.1 < 1.5.3 affected
every other version: unaffected
default status unaffected
cpe cpe:2.3:a:rrrene:html_sanitize_ex:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.HtmlSanitizeEx.Traverser' · 'Elixir.HtmlSanitizeEx'
source files lib/html_sanitize_ex/traverser.ex · lib/html_sanitize_ex.ex
routines 'Elixir.HtmlSanitizeEx.Traverser':traverse/2 · 'Elixir.HtmlSanitizeEx':basic_html/1 · 'Elixir.HtmlSanitizeEx':html5/1 · 'Elixir.HtmlSanitizeEx':markdown_html/1 · 'Elixir.HtmlSanitizeEx':strip_tags/1

Affected — GitHub / rrrene/html_sanitize_ex Repository ↗

69ea11d < 9f5cced affected
every other version: unaffected
default status unaffected
cpe cpe:2.3:a:rrrene:html_sanitize_ex:*:*:*:*:*:*:*:*
modules · source files · routines
modules 'Elixir.HtmlSanitizeEx.Traverser' · 'Elixir.HtmlSanitizeEx'
source files lib/html_sanitize_ex/traverser.ex · lib/html_sanitize_ex.ex
routines 'Elixir.HtmlSanitizeEx.Traverser':traverse/2 · 'Elixir.HtmlSanitizeEx':basic_html/1 · 'Elixir.HtmlSanitizeEx':html5/1 · 'Elixir.HtmlSanitizeEx':markdown_html/1 · 'Elixir.HtmlSanitizeEx':strip_tags/1

Workarounds

Cap the size of user-supplied HTML, and in particular the node count, before it reaches the sanitizer. The quadratic growth means the cap has to be small to be effective.

References

Credits

Peter Ullrich Finder
Jonatan Männchen / EEF Analyst
René Föhring Remediation developer

CVSS breakdown

CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
« All CVEs