Require opt-in to run operator terminal commands on the host - #1358
Open
aditya-786 wants to merge 1 commit into
Open
Require opt-in to run operator terminal commands on the host#1358aditya-786 wants to merge 1 commit into
aditya-786 wants to merge 1 commit into
Conversation
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.
Summary
Closes #1347.
The operator's
terminalaction runs whatever command the model emits. With thedockerprovider this runs inside a container (bash -c ...), but with the defaultlocalprovider it ran on the host viasubprocess.run(command, shell=True)with no gating. A prompt-injected model could therefore execute arbitrary commands as the Khoj process user, and_execute_shell_commandreturned success with no log, so it happened silently.This gates host execution of the
terminalaction behind an explicit opt-in:localprovider) terminal commands are refused unlessKHOJ_OPERATOR_ALLOW_LOCAL_SHELL=trueis set, via a newis_operator_local_shell_allowed()helper that mirrors the existingis_operator_enabled().dockerprovider is unchanged; commands stay sandboxed in the container.logger.warningso execution is no longer silent.Execution is otherwise unchanged; this only adds a default-safe gate around the host path, extracted into
_run_terminal_commandso it is easy to test. Thetext_editor_*actions build their own commands with quoted paths and are out of scope here.This is the minimal default-safe mitigation. If you would prefer a different posture, for example an interactive confirmation step or restricting the operator to the
dockerprovider entirely, I am happy to adjust.Test plan
tests/test_operator_computer.py:_run_terminal_commandrefuses on the host by default (the executor is not called), runs whenKHOJ_OPERATOR_ALLOW_LOCAL_SHELL=true, and is ungated for thedockerprovider.tests/test_helpers.py:is_operator_local_shell_allowed()env var behavior.