Skip to content

Stop sanitizing weblog HTML that takes over a second (6.1.x) - #359

Merged
mraible merged 2 commits into
roller-6.1.xfrom
sanitizer-time-limit-6.1.x
Nov 20, 2026
Merged

mraible merged 2 commits into
roller-6.1.xfrom
sanitizer-time-limit-6.1.x

Conversation

@mraible

@mraible mraible commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

When weblogAdminsUntrusted=true, HTMLSanitizer cleans what weblog users write each time it's shown. On 6.1.x it's still the old regex-based sanitizer, which master replaces with jsoup in #356. Timing it on crafted markup:

  • An 80,000-character style attribute took 43 seconds.
  • An unclosed tag with 20,000 spaces took 2 seconds, and an unclosed url('''… took 1.4 seconds.
  • Output is built by string concatenation, so 640,000 characters of ordinary tags took 4 seconds.

This is the smallest fix for 6.1.8: each sanitize call gets a one-second limit, checked while its expressions read the markup and once per tag, like the banned-words limit in #358. Markup that hits the limit is escaped in full and a warning is logged, so a slow post shows as text instead of holding the request. Ordinary markup is unaffected; a 12,000-character post still takes about 13 ms.

HTMLSanitizerTimeLimitTest timed out before the change and passes after it. The full app suite passes (562 tests, 1 skipped). I also timed the comment HTML subset (Utilities.transformToHTMLSubset) on similar input, and it stays linear, so it isn't changed.

A further review pass added these fixes:

  • The one-second limit also applies while closing tags left open, so markup with tens of thousands of unclosed tags is escaped instead of running for several more seconds.

When weblogAdminsUntrusted=true, HTMLSanitizer cleans what weblog users write each time it's shown. Some of its regular expressions backtrack on crafted markup (an 80,000-character style attribute took 43 seconds), and it builds its output by concatenation, so large posts take quadratic time.

Each sanitize call now has a one-second limit, checked while its expressions read the markup and once per tag. Markup that hits the limit is escaped in full and a warning is logged, so a slow post shows as text instead of holding the request.
@mraible
mraible requested a review from snoopdave November 18, 2026 23:56
@mraible mraible added the 6.1.x label Nov 19, 2026
The loops that close tags left open build their output by string concatenation and did not check the deadline. Markup with tens of thousands of unclosed tags could get through the main loop just inside the one-second limit and then spend several more seconds closing them. Both loops now check the deadline, so that input is escaped like any other that runs out of time.

The time limit test's failure message no longer throws when the output is shorter than 40 characters.

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of c6d2160af: The 6.1.x change covers the slow regex paths and tag-closing loops, and its regression tests exercise the timeout behavior. The twin uses a broader jsoup rewrite; I found no corresponding performance fix missing here. Review was read-only, with no build run.

No new issues found.

@mraible
mraible merged commit 46e6c4e into roller-6.1.x Nov 20, 2026
7 checks passed
@mraible
mraible deleted the sanitizer-time-limit-6.1.x branch November 20, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants