mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(tools): neutralize shell injection in _write_to_sandbox via path quoting (#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.
This commit is contained in:
parent
255f59de18
commit
f2893fe51a
2 changed files with 30 additions and 1 deletions
|
|
@ -24,6 +24,7 @@ Defense against context-window overflow operates at three levels:
|
|||
|
||||
import logging
|
||||
import os
|
||||
import shlex
|
||||
import uuid
|
||||
|
||||
from tools.budget_config import (
|
||||
|
|
@ -79,7 +80,7 @@ def _write_to_sandbox(content: str, remote_path: str, env) -> bool:
|
|||
marker = _heredoc_marker(content)
|
||||
storage_dir = os.path.dirname(remote_path)
|
||||
cmd = (
|
||||
f"mkdir -p {storage_dir} && cat > {remote_path} << '{marker}'\n"
|
||||
f"mkdir -p {shlex.quote(storage_dir)} && cat > {shlex.quote(remote_path)} << '{marker}'\n"
|
||||
f"{content}\n"
|
||||
f"{marker}"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue