wordpress-mobile / wordpress-mobile/GutenbergKit
Escape regex metacharacters in siteApiNamespace before interpolating into RegExp
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29
- Forks
- 6
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
Summary
In src/utils/api-fetch.js, apiPathModifierMiddleware interpolates siteApiNamespace values directly into new RegExp() without escaping regex metacharacters:
const namespaceRegex = new RegExp( `(${ siteApiNamespace.join( '|' ) })` );
If a namespace contained characters like ., +, (, ), *, etc., they would be interpreted as regex syntax rather than matched literally.
Risk
Low — siteApiNamespace comes from the native app bridge config (not user input), so exploitation requires a compromised host app. But it's a latent correctness bug: a namespace like wp/v2.1 would match wp/v2X (. matches any character).
Suggested fix
Escape each namespace before joining:
const escaped = siteApiNamespace.map( ( ns ) =>
ns.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' )
);
const namespaceRegex = new RegExp( `(${ escaped.join( '|' ) })` );
Existing tests in src/utils/api-fetch.test.js pass with this change.
Found during adversarial code review of #TBD.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/utils/api-fetch.js at apiPathModifierMiddleware, then review the related cases in src/utils/api-fetch.test.js. Verify that namespaces containing regex metacharacters are matched literally and that the existing tests still pass; add coverage for the reported namespace example if needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100