Skip to content

fix(terminal): block sudo -S password guessing when SUDO_PASSWORD is unset - #22194

Closed
29206394 wants to merge 1 commit into
NousResearch:mainfrom
29206394:fix/terminal-sudo-password-guard
Closed

fix(terminal): block sudo -S password guessing when SUDO_PASSWORD is unset#22194
29206394 wants to merge 1 commit into
NousResearch:mainfrom
29206394:fix/terminal-sudo-password-guard

Conversation

@29206394

@29206394 29206394 commented May 9, 2026

Copy link
Copy Markdown

Problem (fixes #9590)

The LLM can brute-force sudo passwords by iterating:

echo guessedpass1 | sudo -S whoami  # "Sorry, try again"
echo guessedpass2 | sudo -S whoami  # "Sorry, try again"
# ... iterate based on sudo's error output

The existing _transform_sudo_command only injects -S when SUDO_PASSWORD is configured. Without it, any explicit sudo -S in the command is the LLM piping a guessed password — a brute-force attack vector.

Fix

Add a _check_sudo_stdin_guard() in tools/approval.py:

  • Detects sudo -S (stdin password flag) when SUDO_PASSWORD env var is not set
  • Regex is anchored to command-start positions (^ ; && || | etc.) to avoid false positives on literal text mentions
  • Integrated into check_all_command_guards() above yolo/mode=off, like the hardline floor — this is never legitimate

When SUDO_PASSWORD IS set, the guard is bypassed (the system itself injects -S in that case, which is legitimate).

Changes

File Change
tools/approval.py +44 lines: regex, guard function, block result helper, integration
tests/tools/test_hardline_blocklist.py +88 lines: 6 tests

Tests (6 new, all pass — 246 total in related suites)

  1. detects: sudo -S, piped variants, compound commands with &&
  2. allows: plain sudo, -S on other tools, literal echo text
  3. bypasses when password set: SUDO_PASSWORD configured → no block
  4. integration: check_all_command_guards returns block result
  5. yolo can't bypass: HERMES_YOLO_MODE=1 still blocked
  6. container bypass: docker/singularity/modal/daytona/vercel still skip guards

…not set

Fixes NousResearch#9590: Block explicit sudo -S (stdin password mode) commands
when the SUDO_PASSWORD environment variable is not configured.

The attack vector: the LLM constructs 'echo guessedpass | sudo -S cmd'
to brute-force sudo passwords, iterates based on sudo's error output
('Sorry, try again').  The existing _transform_sudo_command only
injects -S when SUDO_PASSWORD exists; without it, the LLM's explicit
sudo -S must be treated as a guessing attempt.

Changes:
- Add _check_sudo_stdin_guard() in approval.py: detects sudo -S when
  SUDO_PASSWORD is absent, anchored to command-start positions
  (^ ; && || | etc.) to avoid false positives on literal text
- Integrate into check_all_command_guards() above yolo/mode=off so
  the block is unconditional (like the hardline floor)
- Add 6 tests covering: detection, allow-list, SUDO_PASSWORD bypass,
  integration with check_all_command_guards, yolo non-bypass,
  container backend bypass
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P1 High — major feature broken, no workaround comp/tools Tool registry, model_tools, toolsets tool/terminal Terminal execution and process management labels May 9, 2026
kshitijk4poor added a commit that referenced this pull request May 11, 2026
- openclaw@agent.local → 29206394 (PR #22194)
- freedemon@gmail.com  → fr33d3m0n (PR #21128)
kshitijk4poor added a commit that referenced this pull request May 11, 2026
- openclaw@agent.local → 29206394 (PR #22194)
- freedemon@gmail.com  → fr33d3m0n (PR #21128)
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Merged via #23736 (salvage: cherry-picked onto current main). Your commit authorship preserved in git log. Thanks for the fix!

JinyuID pushed a commit to JinyuID/hermes-agent that referenced this pull request May 11, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
jsboige pushed a commit to jsboige/hermes-agent that referenced this pull request May 14, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
AlexFoxD pushed a commit to AlexFoxD/hermes-agent that referenced this pull request May 21, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
Seven74AI pushed a commit to Seven74AI/hermes-agent that referenced this pull request Jun 13, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
- openclaw@agent.local → 29206394 (PR NousResearch#22194)
- freedemon@gmail.com  → fr33d3m0n (PR NousResearch#21128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P1 High — major feature broken, no workaround tool/terminal Terminal execution and process management type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Agent attempts to guess and display sudo password in chat

3 participants