fix(approval): prompt on overwrites inside Hermes credential trees
Prompt before redirection or cp/tee overwrites a vault key, encrypted vault, or MCP OAuth token under the protected credential directories. Preserve the intentional no-prompt behavior for new session transcripts. Follow-up to c2h5oh's PR #155452 and denysgaievskyi's report #109367. (cherry picked from commit fd834173c3aa02232eb1781a6477ce3e8aa20137)
This commit is contained in:
committed by
Maciej Lisiewski
parent
5009935d40
commit
0612c32f51
@@ -123,3 +123,17 @@ def test_repeated_heredoc_lines_stay_linear(home):
|
||||
started = time.monotonic()
|
||||
assert detect_dangerous_command(command)[0] is True
|
||||
assert time.monotonic() - started < 6
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template", (
|
||||
"echo wiped > {h}/vault/vault.key",
|
||||
"cp /dev/null {h}/vault/vault.json.enc",
|
||||
"echo revoked | tee {h}/mcp-tokens/fixture.json",
|
||||
))
|
||||
def test_credential_tree_overwrites_prompt(home, template):
|
||||
# The file tools deny writes anywhere inside these protected credential trees;
|
||||
# an equivalent terminal overwrite must not silently bypass approval.
|
||||
command = template.format(h=home)
|
||||
dangerous, key, _ = detect_dangerous_command(command)
|
||||
assert dangerous is True, command
|
||||
assert key is not None
|
||||
|
||||
@@ -19,10 +19,14 @@ _HERMES_STORE_FILE = (
|
||||
re.escape(sub) + (r'(?:-wal|-shm|-journal)?' if sub.endswith('.db') else r'(?:/[^\s"\'`;|&<>()]*)?')
|
||||
for sub in HERMES_PROTECTED_SUBPATHS) + r')' + _PATH_WORD_END
|
||||
)
|
||||
# The store itself, for the overwrite rules: a new file written into sessions/ (`> sessions/x`) stays clean.
|
||||
# Overwrites inside credential directories must prompt (vault.key, MCP OAuth tokens, browser cookies).
|
||||
# New session transcript files stay clean, as before; only the sessions/ root is an overwrite target.
|
||||
_HERMES_STORE_ROOT = (
|
||||
_HERMES_HOME_ROOT + r'/(?:' + '|'.join(
|
||||
re.escape(sub) + (r'(?:-wal|-shm|-journal)?' if sub.endswith('.db') else r'/?')
|
||||
re.escape(sub) + (
|
||||
r'(?:-wal|-shm|-journal)?' if sub.endswith('.db')
|
||||
else r'/?' if sub == 'sessions' else r'(?:/[^\s"\'`;|&<>()]*)?'
|
||||
)
|
||||
for sub in HERMES_PROTECTED_SUBPATHS) + r')' + _PATH_WORD_END
|
||||
)
|
||||
_HERMES_HOME_BARE = rf'{_HERMES_HOME_ROOT}/?\*?{_PATH_WORD_END}'
|
||||
|
||||
Reference in New Issue
Block a user