gabriel / muse public
patch task/agent-id-traversal-guard #1 / 1
AI Agent gabriel · 162 days ago · Apr 17, 2026 · Diff

security: reject path traversal in agent_id for PEM filename construction

agent_id was appended verbatim to the PEM filename: ~/.muse/keys/{hostname}__{agent_id}.pem

A malicious agent_id like '../../.bashrc' resolves outside ~/.muse/keys/ via pathlib, allowing writes to arbitrary filesystem locations.

Add _SAFE_AGENT_ID regex (alphanumerics, hyphens, underscores, dots only). _key_path raises ValueError before constructing the path if agent_id fails the check. The end-to-end keygen path propagates this as a non-zero exit.

8 tests in test_agent_id_traversal.py.

sha256:1537a688fc95dd7bbcfd9effddf74a5b45767da3956de747ce529c487e768a19 sha
+24 ~1 symbols
sha256:eb0d5a2b84b6bad63b5d9a02797240419276241eeb4b56200ee3658eed85c7d5 snapshot
+24
symbols added
~1
symbol modified
0
dead code introduced
Semantic Changes 25 symbols
~ tests/test_agent_id_traversal.py .py 22 symbols added
+ TestKeyPathSafeAgentId class class TestKeyPathSafeAgentId L94–108
+ test_II1_alphanumeric_accepted method method test_II1_alphanumeric_accepted L95–98
+ test_II2_hyphens_underscores_accepted method method test_II2_hyphens_underscores_accepted L100–103
+ test_II3_internal_dot_accepted method method test_II3_internal_dot_accepted L105–108
+ TestKeyPathTraversalRejected class class TestKeyPathTraversalRejected L68–87
+ test_I1_dotdot_slash_rejected method method test_I1_dotdot_slash_rejected L69–72
+ test_I2_leading_slash_rejected method method test_I2_leading_slash_rejected L74–77
+ test_I3_backslash_rejected method method test_I3_backslash_rejected L79–82
+ test_I4_null_byte_rejected method method test_I4_null_byte_rejected L84–87
+ TestKeygenTraversalEndToEnd class class TestKeygenTraversalEndToEnd L115–128
+ test_III1_keygen_traversal_agent_id_rejected method method test_III1_keygen_traversal_agent_id_rejected L116–128
+ _HUB variable variable _HUB L39–39
+ _MNEMONIC variable variable _MNEMONIC L40–43
+ fixed_mnemonic function function fixed_mnemonic L58–61
+ CliRunner import import CliRunner L36–36
+ annotations import import annotations L28–28
+ id_module import import id_module L35–35
+ kp_module import import kp_module L34–34
+ pathlib import import pathlib L30–30
+ pytest import import pytest L32–32
+ isolated function function isolated L47–54
+ runner variable variable runner L38–38
~ muse/core/keypair.py .py 2 symbols added, 1 symbol modified
+ _SAFE_AGENT_ID variable variable _SAFE_AGENT_ID L79–79
+ re import import re L45–45
← Older Oldest on task/agent-id-traversal-guard
All commits
Newer → Latest on task/agent-id-traversal-guard

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:1537a688fc95dd7bbcfd9effddf74a5b45767da3956de747ce529c487e768a19 --body "your comment"