Skip to content

fix(security): reduce unnecessary shell=True in subprocess calls#25149

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-f85c5421
May 13, 2026
Merged

fix(security): reduce unnecessary shell=True in subprocess calls#25149
teknium1 merged 2 commits into
mainfrom
hermes/hermes-f85c5421

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #6155 (@iuyup) onto current main.

Drops shell=True from two subprocess sites where the input isn't a user-authored shell snippet:

  • Auto-detected whisper STT command (tools/transcription_tools.py) — args are already shlex.quote'd, so list mode is strictly safer. User templates via HERMES_LOCAL_STT_COMMAND still use shell mode (may contain pipes/redirects).
  • Memory-plugin external_dependencies.check field (hermes_cli/memory_setup.py) — also adds check=True so the install hint actually fires (was previously dead code).

cli.py quick_commands keeps shell=True with a clarifying comment — that path is user-defined config, not agent-controlled.

Changes

  • tools/transcription_tools.py: shell/list branching on env var presence
  • hermes_cli/memory_setup.py: shlex.split + check=True
  • cli.py: intent comment on quick_commands
  • tests/tools/test_transcription_tools.py: new TestShellSafety class (3 tests)
  • scripts/release.py: AUTHOR_MAP entry for contributor

Validation

Suite Before After
tests/tools/test_transcription_tools.py 92/92 95/95
tests/agent/test_memory_provider.py + test_hindsight_provider.py 158/158 158/158

Closes #6155.

Co-authored-by: iuyup 23yntong@stu.edu.cn

iuyup and others added 2 commits May 13, 2026 10:30
- memory_setup.py: use shlex.split() for plugin dep checks instead of shell=True
- transcription_tools.py: avoid shell=True for auto-detected whisper commands
  (user-provided templates via env var still use shell=True for compatibility)
- cli.py: add comment clarifying intentional shell=True for user quick_commands
- Add test verifying auto-detected template is shlex-safe

Addresses CONTRIBUTING.md Priority #3 (Security hardening — shell injection).
@teknium1 teknium1 force-pushed the hermes/hermes-f85c5421 branch from 674e3d6 to e65af81 Compare May 13, 2026 17:31
@teknium1 teknium1 merged commit 1979ef5 into main May 13, 2026
@teknium1 teknium1 deleted the hermes/hermes-f85c5421 branch May 13, 2026 17:31
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-f85c5421 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: 8252 on HEAD, 8252 on base (➖ 0)

🆕 New issues (3):

Rule Count
invalid-argument-type 3
First entries
run_agent.py:13591: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown | str, Unknown | str | dict[str, str]] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
run_agent.py:13588: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`
run_agent.py:7391: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`

✅ Fixed issues (3):

Rule Count
invalid-argument-type 3
First entries
run_agent.py:13588: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:7391: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:13591: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown, Unknown] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`

Unchanged: 4330 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 P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard tool/tts Text-to-speech and transcription labels May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists tool/tts Text-to-speech and transcription type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants