Skip to content

fix(security): close shell-escape denylist bypass + fail-closed on missing approval module (#36846, #36847)#40591

Merged
teknium1 merged 2 commits into
mainfrom
salvage/40370-cmd-escape-bypass
Jun 7, 2026
Merged

fix(security): close shell-escape denylist bypass + fail-closed on missing approval module (#36846, #36847)#40591
teknium1 merged 2 commits into
mainfrom
salvage/40370-cmd-escape-bypass

Conversation

@teknium1

@teknium1 teknium1 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes two ways to bypass dangerous-command detection. Closes #36846 and #36847.

  1. Shell-escape bypass (tools/approval.py): the denylist normalizer didn't account for shell tokenization, so r\\m -rf / and r''m -rf / slipped past detection (returned dangerous=False) while the shell still executed them as rm -rf /. The normalizer now strips backslash-escapes and empty-string literals before matching.
  2. Fail-open on missing safety module (tui_gateway/server.py): shell.exec did except ImportError: pass, running the command with no safety check if tools.approval failed to import. Now fails closed (returns an error) and also blocks hardline commands via detect_hardline_command.

Validation

Live-verified the bypass on main (r\\m -rf /dangerous=False) and after the fix (→ True); rm -rf / still caught, ls -la still benign. Regression tests added (4 passed).

Cherry-picked from #40370 (@ashishpatel26), authorship preserved; added regression tests.

ashishpatel26 and others added 2 commits June 6, 2026 08:26
…d on missing approval module

DANGEROUS_PATTERNS and HARDLINE_PATTERNS are matched on the raw command string,
so backslash-escape (r\m) and empty-quote split (r''m) bypass both lists.
_normalize_command_for_detection now strips these before pattern matching.

tui_gateway shell.exec had a bare 'except ImportError: pass' that silently
disabled the entire safety gate if tools.approval wasn't importable. Changed
to fail-closed (return 5001 error). Added detect_hardline_command check.

Fixes #36846, #36847.
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/40370-cmd-escape-bypass vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9962 on HEAD, 9962 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5167 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P1 High — major feature broken, no workaround comp/tools Tool registry, model_tools, toolsets comp/gateway Gateway runner, session dispatch, delivery labels Jun 6, 2026
@teknium1 teknium1 merged commit 1a4010e into main Jun 7, 2026
23 checks passed
@teknium1 teknium1 deleted the salvage/40370-cmd-escape-bypass branch June 7, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/tools Tool registry, model_tools, toolsets P1 High — major feature broken, no workaround type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: dangerous-command denylist (DANGEROUS_PATTERNS / HARDLINE_PATTERNS) is bypassable with trivial shell escapes → silent RCE

3 participants