Skip to content

fix(exec): escape regex metacharacters in allowlist path matcher#32162

Merged
steipete merged 2 commits intoopenclaw:mainfrom
stakeswky:fix/32145-exec-allowlist-regex-escape-v2
Mar 2, 2026
Merged

fix(exec): escape regex metacharacters in allowlist path matcher#32162
steipete merged 2 commits intoopenclaw:mainfrom
stakeswky:fix/32145-exec-allowlist-regex-escape-v2

Conversation

@stakeswky
Copy link

Summary

  • fix exec allowlist path matching to escape regex literal characters before compiling patterns
  • keep wildcard semantics (*, **, ?) while preventing invalid regex creation for paths like /usr/bin/g++
  • add regression coverage for /usr/bin/g++ and /usr/bin/clang++

Repro

Before this change, allowing a binary path containing + could crash regex creation with:

Invalid regular expression: /^/usr/bin/g++$/i: Nothing to repeat

Validation

  • pnpm vitest run src/infra/exec-approvals.test.ts

Fixes #32145

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Fixes exec allowlist path matching crash when paths contain regex metacharacters (notably + in /usr/bin/g++). The fix extracts regex escaping logic into a dedicated escapeRegExpLiteral function that properly escapes all regex metacharacters (.*+?^${}()|[]\) while preserving glob wildcard semantics (*, **, ?).

Key improvements:

  • Prevents regex compilation errors: "Nothing to repeat" errors from paths like /usr/bin/g++ are now prevented
  • Cleaner implementation: extracted escaping logic into a reusable helper function
  • Comprehensive test coverage: added tests for paths with ++ and wildcard-metacharacter combinations (/usr/bin/*++)

Technical details:

  • The globToRegExp function now processes wildcards first (converting * to [^/]*, ** to .*, ? to .), then escapes all other characters through escapeRegExpLiteral
  • All regex metacharacters are uniformly handled, making the fix robust for any future edge cases
  • The removed test "requires a resolved path" is still functionally covered by other test files

Confidence Score: 5/5

  • This PR is safe to merge with no concerns
  • The fix is focused, correct, and well-tested. It addresses a specific crash bug without introducing side effects. The regex escaping logic is comprehensive (covers all metacharacters), the control flow is correct (wildcards are processed before escaping), and the test coverage validates both the core bug and edge cases. The implementation improves code clarity by extracting the escaping logic into a named function.
  • No files require special attention

Last reviewed commit: 6861d7e

@steipete steipete force-pushed the fix/32145-exec-allowlist-regex-escape-v2 branch from 6861d7e to 559a129 Compare March 2, 2026 21:26
@steipete steipete merged commit 21d6d87 into openclaw:main Mar 2, 2026
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm -s vitest run src/infra/exec-approvals.test.ts src/infra/exec-approvals-parity.test.ts src/infra/exec-approvals-safe-bins.test.ts
  • Land commit: 559a1295fd687474e55f669b83cb2f719bc98c39
  • Merge commit: 21d6d87

Thanks @stakeswky!

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 2, 2026
* main: (154 commits)
  fix: harden exec allowlist regex literal handling (openclaw#32162) (thanks @stakeswky)
  fix(exec): escape regex literals in allowlist path matching
  fix: OpenAI OAuth TLS preflight gating (openclaw#32051) (thanks @alexfilatov)
  Auth: gate OpenAI OAuth TLS preflight in doctor
  Fix TLS cert preflight classification false positive
  Add OpenAI OAuth TLS preflight and doctor prerequisite check
  fix(gateway): hot-reload channelHealthCheckMinutes without full restart
  refactor: harden plugin install flow and main DM route pinning
  fix: propagate whatsapp inbound fromMe context (openclaw#32167) (thanks @scoootscooob)
  fix(whatsapp): propagate fromMe through inbound message pipeline
  refactor: harden msteams lifecycle and attachment flows
  fix(config): move sensitive-schema hint warnings to debug
  test(perf): reduce heavy fixture and guardrail overhead
  perf(core): speed up routing, pairing, slack, and security scans
  refactor: unify queueing and normalize telegram slack flows
  fix: harden bundled plugin install fallback semantics (openclaw#32096) (thanks @scoootscooob)
  fix(plugins): prefer bundled plugin ids over bare npm specs
  fix: distinguish warning message for non-OpenClaw vs missing npm package
  fix(plugins): fall back to bundled plugin when npm spec resolves to non-OpenClaw package (openclaw#32019)
  fix: harden msteams revoked-context fallback delivery (openclaw#27224) (thanks @openperf)
  ...
dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
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.

[Bug]: Exec runner crashes on unescaped binary path (/usr/bin/g++) with invalid regex “Nothing to repeat”

2 participants