Skip to content

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

Open
mraible wants to merge 1 commit into
masterfrom
banned-words-time-limit
Open

mraible wants to merge 1 commit into
masterfrom
banned-words-time-limit

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.

The full unit suite passes (762 tests). The 6.1.x change is a separate PR.

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.
@mraible
mraible requested a review from snoopdave November 18, 2026 17:50
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