Skip to content

Stop a banned words rule that backtracks without end - #358

Merged
mraible merged 1 commit into
roller-6.1.xfrom
banned-words-time-limit-6.1.x
Nov 20, 2026
Merged

mraible merged 1 commit into
roller-6.1.xfrom
banned-words-time-limit-6.1.x

Conversation

@mraible

@mraible mraible commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Banned words rules are regular expressions: rules that start with ( directly, and every other rule as \b(rule)\b. A weblog's own banned words and the site's list are compiled as written, so a rule like ((x+)+)+y held a comment post or a referrer check for as long as it backtracked. CodeQL flags this as regex injection (alert 95). A comment post checks the commenter's name, e-mail, URL and text.

  • Each value is now matched through a CharSequence that stops the match once 1 second has passed.
  • The value then counts as a match, so a comment that sets off such a rule is caught as spam, and the rule is logged so it can be simplified.
  • Ordinary checks take a few milliseconds; 40,000 characters against the bundled list take about 24 ms.

The new BannedwordslistTest case uses ((x+)+)+y as a regex rule and as a word rule. It timed out before the fix on both lines and passes after.

This is the master change cherry-picked; the 6.1.x unit suite passes (561 tests, 1 skipped).

Banned words rules are regular expressions: rules that start with ( directly, and every other rule as \b(rule)\b. A weblog's own banned words and the site's list are compiled as written, so a rule like ((x+)+)+y held a comment post (checked against the commenter's name, e-mail, URL and text) or a referrer check for as long as it backtracked, which CodeQL flags as regex injection.

Each value is now matched through a CharSequence that stops the match once 1 second has passed. The value then counts as a match, so a comment that sets off such a rule is caught as spam, and the rule is logged so it can be simplified. Ordinary checks take a few milliseconds; 40,000 characters against the bundled list take about 24 ms.

(cherry picked from commit 805dbc6)

@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 95acc639f: The timeout covers both banned-words matching paths, and the new test would fail without it. Master's #357 also makes weblog rules plain words; a timeout alone is a reasonable scope for 6.1.8.

No new issues found.

@mraible
mraible merged commit d8f6274 into roller-6.1.x Nov 20, 2026
7 checks passed
@mraible
mraible deleted the banned-words-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