Skip to content

Fix ReDoS in stripHtml - #308

Open
y0d4a wants to merge 1 commit into
rbren:masterfrom
y0d4a:agent/fix-redos-strip-html
Open

Fix ReDoS in stripHtml#308
y0d4a wants to merge 1 commit into
rbren:masterfrom
y0d4a:agent/fix-redos-strip-html

Conversation

@y0d4a

@y0d4a y0d4a commented Aug 14, 2026

Copy link
Copy Markdown

stripHtml() can exhibit quadratic runtime on malformed HTML containing repeated unterminated tags.

The current regex may repeatedly scan the remaining input while searching for a closing >, allowing crafted RSS/Atom content to block the Node.js event loop.

This change prevents tag matching from crossing another <, bounding each attempted match and avoiding the pathological repeated scanning behavior.

A regression test was added using ~160 KB of repeated unterminated <br sequences.

Benchmark on Node.js v22.16.0 with the same 160 KB input:

  • Before: ~18.9 s
  • After: ~1.08 ms

The patch is intentionally minimal and does not add dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant