Skip to content

fix(tools): neutralize shell injection in _write_to_sandbox via path quoting#7940

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-67b0d759
Apr 11, 2026
Merged

fix(tools): neutralize shell injection in _write_to_sandbox via path quoting#7940
teknium1 merged 1 commit into
mainfrom
hermes/hermes-67b0d759

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

_write_to_sandbox in tools/tool_result_storage.py interpolated storage_dir and remote_path directly into a shell command passed to env.execute(). If either path contained shell metacharacters (spaces, semicolons, $(), backticks), the result was arbitrary command execution inside the sandbox.

Before:

f"mkdir -p {storage_dir} && cat > {remote_path} << '{marker}'"

After:

f"mkdir -p {shlex.quote(storage_dir)} && cat > {shlex.quote(remote_path)} << '{marker}'"

shlex.quote() leaves clean paths (alphanumeric + slashes/hyphens/dots/underscores) unmodified, so existing behavior is unchanged. Paths with unsafe characters get single-quoted.

The heredoc body was already safe (single-quoted delimiter prevents shell expansion).

Changes

  • tools/tool_result_storage.py: added import shlex, quoted both path interpolations
  • tests/tools/test_tool_result_storage.py: 3 new tests covering spaces, $(command) substitution, and semicolon injection

Test plan

python3 -m pytest tests/tools/test_tool_result_storage.py -o 'addopts=' -q
# 48 passed (45 existing + 3 new)

…quoting

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
@teknium1 teknium1 force-pushed the hermes/hermes-67b0d759 branch from 9f86c2d to 436649f Compare April 11, 2026 21:26
@teknium1 teknium1 merged commit f2893fe into main Apr 11, 2026
1 check passed
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
dev-xyz-0-0 added a commit to dev-xyz-0-0/hermes-agent that referenced this pull request May 27, 2026
…quoting

_write_to_sandbox in tools/tool_result_storage.py interpolated storage_dir and remote_path directly into a shell command passed to env.execute(). If either path contained shell metacharacters (spaces, semicolons, $(), backticks), the result was arbitrary command execution inside the sandbox.

Before:

f"mkdir -p {storage_dir} && cat > {remote_path} << '{marker}'"
After:

f"mkdir -p {shlex.quote(storage_dir)} && cat > {shlex.quote(remote_path)} << '{marker}'"
shlex.quote() leaves clean paths (alphanumeric + slashes/hyphens/dots/underscores) unmodified, so existing behavior is unchanged. Paths with unsafe characters get single-quoted.

The heredoc body was already safe (single-quoted delimiter prevents shell expansion).

Changes
tools/tool_result_storage.py: added import shlex, quoted both path interpolations
tests/tools/test_tool_result_storage.py: 3 new tests covering spaces, $(command) substitution, and semicolon injection

NousResearch/hermes-agent#7940
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…quoting (NousResearch#7940)

_write_to_sandbox interpolated storage_dir and remote_path directly into
a shell command passed to env.execute(). Paths containing shell
metacharacters (spaces, semicolons, $(), backticks) could trigger
arbitrary command execution inside the sandbox.

Fix: wrap both paths with shlex.quote(). Clean paths (alphanumeric +
slashes/hyphens/dots) are left unmodified by shlex.quote, so existing
behavior is unchanged. Paths with unsafe characters get single-quoted.

Tests added for spaces, $(command) substitution, and semicolon injection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant