fix(security): route tui_gateway shell.exec through the sanitized env builder - #78036
Open
andrexibiza wants to merge 2 commits into
Open
fix(security): route tui_gateway shell.exec through the sanitized env builder#78036andrexibiza wants to merge 2 commits into
andrexibiza wants to merge 2 commits into
Conversation
… builder The registered shell.exec handler (@method('shell.exec') in methods_tools.py) spawned every approved quick command with subprocess.run(cmd, shell=True) and no env=, inheriting the gateway's full os.environ — provider keys, gateway tokens, *_PASSWORD values. The sibling cli.exec path already sanitizes via build_subprocess_env(); shell.exec now does the same. (The duplicate shell.exec copy in tui_gateway/server.py is covered by open PR NousResearch#60423.) Regression test: real shell.exec handler run with EMAIL_PASSWORD planted in the parent env asserts the child env is scrubbed. Full tests/tui_gateway/ suite: 338 passed; the 3 failures reproduce identically on clean origin/main on this Windows/MSYS box. diff-check and Windows-footgun lint clean. Signed-off-by: Andrex Ibiza, MBA <84248988+andrexibiza@users.noreply.github.com>
Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
This was referenced Aug 4, 2026
refactor(tui): extract pet payload into tui_gateway/pet_payload (server.py god-file slice R3)
#79261
Open
Open
19 tasks
Contributor
|
looks mergeable shell.exec now supplies a sanitized child environment through the shared builder, removing Hermes-managed credentials while preserving ordinary command variables. The current-main inheritance leak is closed, and no residual bypass was found in the reviewed TUI shell or quick-command paths. Security evidence:
Not checked:
Signed: GPT-5.6-luna-max in Codex |
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.
Related #60423
What changed and why
tui_gateway's registeredshell.exechandler (@method("shell.exec")intui_gateway/methods_tools.py) ran every approved quick command withsubprocess.run(cmd, shell=True, ...)and noenv=— the spawned shell inherited the gateway process's fullos.environ, including provider API keys, gateway tokens, and*_PASSWORDvalues. The siblingcli.execpath in the same module already sanitizes viabuild_subprocess_env();shell.execnow does the same, so a command run through it cannot read Hermes-managed credentials.This covers the registered
methods_toolshandler; open PR #60423 addresses the duplicateshell.execcopy intui_gateway/server.py— the two are complementary (different seams, same fix pattern).How to test
python -m pytest tests/tui_gateway/test_shell_exec_sanitized_env.py -q→ 1 passedtest_shell_exec_spawns_with_sanitized_env: plantsEMAIL_PASSWORDin the parent env, runs the realshell.exechandler, asserts the child env is scrubbed.tests/tui_gateway/suite: 338 passed; the 3 failures are proven pre-existing on cleanorigin/main(identical on this Windows/MSYS box:signal.SIGPIPE-on-Windows and two timing tests).git diff --checkclean;check-windows-footguns.pyclean on both changed files.Platforms tested
Windows 11 (git-bash), Python 3.11, direct pytest (
scripts/run_tests.shis POSIX-only on native Windows).Why this matters to users
Every command you approve and run through the desktop app's quick-command surface used to carry the gateway's API keys and database passwords into the shell. After this change, that shell gets the same sanitized environment as the agent's other exec paths — your secrets stay out of processes that never asked for them.
Part of #78207
Part of #78630
Part of #83565 — tui_gateway shell.exec through the sanitized builder; Wave D, merge lane via #60423.