Repository navigation
Stop sanitizing weblog HTML that takes over a second (6.1.x) - #359
Merged
Merged
Conversation
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.
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
reviewed
Nov 20, 2026
snoopdave
left a comment
Contributor
There was a problem hiding this comment.
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.
snoopdave
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
weblogAdminsUntrusted=true,HTMLSanitizercleans 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:styleattribute took 43 seconds.url('''…took 1.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.
HTMLSanitizerTimeLimitTesttimed 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: