Repository navigation
fix(qqbot): guard mentionPatterns against ReDoS via compileSafeRegex - #102976
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 12, 2026, 9:06 PM ET / July 13, 2026, 01:06 UTC. Summary PR surface: Source +54, Tests +53. Total +107 across 2 files. Reproducibility: yes. The PR supplies a concrete raw-RegExp timing reproduction and after-fix detectWasMentioned output, and the inspected current-main path matches that reproduction. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: Retain the shared safe-regex compiler and bounded reason-aware diagnostics, replace the cache key with collision-free ordered-array encoding or remove the cache, and add a sequential-call collision regression test. Do we have a high-confidence way to reproduce the issue? Yes. The PR supplies a concrete raw-RegExp timing reproduction and after-fix detectWasMentioned output, and the inspected current-main path matches that reproduction. Is this the best way to solve the issue? No, not yet. Reusing the shared safe-regex contract is the right boundary, but the new cache must identify ordered pattern arrays without collisions before this is the narrowest correct solution. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6c884691105b. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +54, Tests +53. Total +107 across 2 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (5 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
fa7df54 to
340105b
Compare
340105b to
dfc7157
Compare
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(qqbot): guard mentionPatterns against ReDoS via compileSafeRegex This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
dfc7157 to
03bafe6
Compare
Co-authored-by: hugenshen <[email protected]>
03bafe6 to
5a5de04
Compare
|
Merged via squash.
|
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit c93f877)
What Problem This Solves
Fixes a ReDoS vulnerability where operator-configured
mentionPatternsin the QQBotplugin were compiled with bare
new RegExp(pattern, "i")without any safety check.A pattern containing nested repetition such as
(a+)+$compiles successfully butcauses catastrophic backtracking when matched against attacker-controlled message
content, pushing CPU to 100% and making the gateway unresponsive.
Attack chain: set
mentionPatterns: ["(a+)+$"]in config → attacker sends a messagewith a long run of
'a'characters → regex match never terminates → DoS.The same class of bug was previously fixed in MCP glob patterns (#100330).
compileSafeRegexfromsrc/security/safe-regex.tsis already exposed throughopenclaw/plugin-sdk/security-runtimefor exactly this use.Why This Change Was Made
Replace
new RegExp(pattern, "i")withcompileSafeRegex(pattern, "i"). The helperrejects patterns with nested repetition and returns
nullfor both unsafe and invalidpatterns, so the loop simply skips them — same observable behavior as before for valid
safe patterns, silent rejection for dangerous ones.
User Impact
Before: An operator (or anyone with config write access) could configure a
mentionPatternsentry that causes the gateway process to spin at 100% CPU whena matching message arrives.
After: Patterns with nested repetition are rejected at match time and skipped.
Safe patterns continue to work normally.
Evidence
Node: v22.22.0 — macOS Darwin 24.3.0 arm64
LOC —
extensions/qqbot/src/engine/group/mention.ts: +4/−5 (import + replace).extensions/qqbot/src/engine/group/mention.test.ts: +20 (2 new regression cases).Before — catastrophic backtracking via raw
new RegExp:Each +2 characters roughly 4× the time (exponential growth). At 64 characters the gateway
process would be unresponsive for minutes.
After —
compileSafeRegexguard, constant-time rejection:The guard rejects the pattern at compile time;
detectWasMentionedreturnsfalseinsub-millisecond time regardless of input length.
Safe pattern still matches after a rejected unsafe one:
Regression tests — 24/24:
rejects ReDoS patterns via compileSafeRegex guard: passes(a+)+$with a 64-char'a'input — assertsfalseis returned instantly rather than hanging.still matches safe patterns after a rejected unsafe one: confirms the unsafe patternis skipped and the next safe pattern still matches.
What was not tested: live QQBot message delivery with a real QQ group.
Crabbox/Testbox remote CI was not run at submission time.
Related: #100330 (MCP glob ReDoS — same fix pattern)