Skip to content

Fix ReDoS in mu-plugins loader path regex - #4254

Merged
wojtekn merged 1 commit into
trunkfrom
fix-mu-plugins-redos
Jul 23, 2026
Merged

Fix ReDoS in mu-plugins loader path regex#4254
wojtekn merged 1 commit into
trunkfrom
fix-mu-plugins-redos

Conversation

@wojtekn

@wojtekn wojtekn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Related issues

  • Related to code scanning alert #204 (js/redos, CWE-1333, high severity)

How AI was used in this PR

Claude Code fetched the code scanning alert, identified the ambiguous regex branch causing exponential backtracking, applied the fix, and verified correctness and timing. All human-reviewed.

Proposed Changes

The regex that reads the mu-plugins directory path back out of the generated loader plugin ($studio_mu_plugins_dir = '...') had ambiguous alternatives: its catch-all branch [^'] also matched a lone backslash, overlapping with the \\ and \' escape branches. A path containing many consecutive backslashes could therefore be matched multiple ways, triggering catastrophic (exponential) backtracking — a ReDoS. In practice this is reached when Studio parses an existing native-PHP loader file, so a malformed/crafted loader path could hang the process.

The fix excludes backslash from the catch-all branch ([^\\']), making the three alternatives mutually exclusive while still matching exactly what PHP single-quote escaping produces. No behavior change for valid paths.

Testing Instructions

  • npm test -- packages/common/lib/tests/mu-plugins.test.ts — all 12 tests pass.
  • Verified a path containing backslashes and quotes still round-trips correctly through escape/unescape.
  • Verified timing: a malicious input (~40 backslashes) previously took ~3940 ms to reject and now rejects in ~0.04 ms.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
The regex parsing $studio_mu_plugins_dir had ambiguous alternatives that
allowed exponential backtracking on inputs with many backslashes. Exclude
backslash from the catch-all branch so the alternatives are mutually
exclusive.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wojtekn
wojtekn requested a review from a team July 20, 2026 10:13
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 4bb49ca vs trunk

app-size

Metric trunk 4bb49ca Diff Change
App Size (Mac) 1355.57 MB 1355.57 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 4bb49ca Diff Change
load 1086 ms 1127 ms +41 ms ⚪ 0.0%

site-startup

Metric trunk 4bb49ca Diff Change
siteCreation 6984 ms 7010 ms +26 ms ⚪ 0.0%
siteStartup 2357 ms 2349 ms 8 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@wojtekn
wojtekn requested a review from youknowriad July 20, 2026 11:51
@wojtekn
wojtekn merged commit ecfbf2d into trunk Jul 23, 2026
14 checks passed
@wojtekn
wojtekn deleted the fix-mu-plugins-redos branch July 23, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants