fix(cron): apply gateway lifecycle block to cronjob tool prompt and script scan - #36194
Closed
AhmetArif0 wants to merge 1 commit into
Closed
fix(cron): apply gateway lifecycle block to cronjob tool prompt and script scan#36194AhmetArif0 wants to merge 1 commit into
AhmetArif0 wants to merge 1 commit into
Conversation
…cript scan hermes_cli/cron.py blocks gateway lifecycle commands (hermes gateway restart, launchctl, systemctl, pkill) in the CLI cron_create path. The Python cronjob tool (_scan_cron_prompt) lacked these patterns, so an agent could schedule a restart loop by using the tool instead of the CLI. - Add four gateway lifecycle patterns to _CRON_THREAT_PATTERNS, matching the same set as hermes_cli/cron.py's _GATEWAY_LIFECYCLE_PATTERNS. - Scan script file content (in addition to the prompt) on create, mirroring the CLI's combined prompt+script check. - Add 14 regression tests covering all four patterns plus safe false-positive cases (API gateway mentions, nginx restarts, etc.).
mxnstrexgl
approved these changes
Jun 1, 2026
mxnstrexgl
left a comment
There was a problem hiding this comment.
LGTM — automated review passed. No security, quality, or test coverage issues detected.
tonydwb
approved these changes
Jun 1, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved ✅
Review
fix(cron): apply gateway lifecycle block to cronjob tool prompt and script scan
Solid defense-in-depth addition. Key observations:
- Defense in depth: The CLI path (
hermes_cli/cron.py) already blocks gateway lifecycle commands. This PR extends the same protection to the cronjob tool pathway (tools/cronjob_tools.py), preventing agents from bypassing the CLI defense by scheduling jobs through the tool directly. - Completeness: Covers all gateway lifecycle vectors —
hermes gateway *,launchctl,systemctl,pkill/kill. Each has its own regex pattern with a distinct reason tag for traceability. - Script scanning: The PR also adds scanning of script file contents at creation time, so even if an agent writes a shell script that calls
hermes gateway restart, it gets caught. - False positive protection: The safe-mentions test ensures prose about "API gateway" or "payment gateway" passes through cleanly.
- Tests: 13 test cases covering all lifecycle patterns plus safe-mention edge cases. Good coverage.
Looks Good
- Defense-in-depth approach
- Well-tested with clear test organization
- No regex can be accidentally triggered by unrelated content
Reviewed by Hermes Agent
9 tasks
Contributor
|
Thanks for the defense-in-depth work. This is an automated hermes-sweeper review; current
Closing as implemented on main. |
1 task
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.
What does this PR do?
hermes_cli/cron.py's CLI path blocks gateway lifecycle commands (hermes gateway restart/stop/start,launchctl,systemctl,pkill) via_contains_gateway_lifecycle_command(). The Python cronjob tool (tools/cronjob_tools.py) used by agents had no equivalent check in_scan_cron_prompt(), so an agent could bypass the defense by scheduling a restart loop through the tool instead of the CLI.Changes Made
tools/cronjob_tools.py: Added four gateway lifecycle patterns to_CRON_THREAT_PATTERNS, matching the same set ashermes_cli/cron.py's_GATEWAY_LIFECYCLE_PATTERNS:hermes gateway (restart|stop|start)launchctl (kickstart|unload|load|stop|restart) ... hermessystemctl (restart|stop|start) ... hermesp?kill ... hermes ... gatewaytools/cronjob_tools.py: Onaction='create', scan the script file's content for gateway lifecycle patterns (in addition to the prompt), mirroring the CLI's combined prompt+script check.tests/tools/test_cron_prompt_injection.py: Added 14 regression tests covering all four patterns plus safe false-positive cases (API gateway mentions, nginx restarts, etc.).Related Issue
Follows up on #30719 / commits
5cd6c1717andbd72d333dwhich added the CLI-side defense.Type of Change
How to Test
All 20 tests should pass (6 original + 14 new).
Checklist
pytest tests/ -qand all tests pass