Skip to content

Commit 69dd0f7

Browse files
JasonOA888teknium1
authored andcommitted
fix(approval): extend sensitive write target to cover shell RC and credential files
Terminal commands can write to shell RC files (~/.bashrc, ~/.zshrc, ~/.profile) and credential files (~/.netrc, ~/.pgpass, ~/.npmrc, ~/.pypirc) via redirection or tee without triggering approval, even though write_file already blocks these paths in file_safety.py. This creates an inconsistency: write_file protects these paths but terminal shell redirections bypass the same protection. An agent prompted via indirect injection could install persistent backdoors (e.g. PATH manipulation, alias overrides) or write credential entries without user approval. Extend _SENSITIVE_WRITE_TARGET with two new regex groups matching the same paths that file_safety.py's WRITE_DENIED_PATHS already covers: _SHELL_RC_FILES — ~/.bashrc, ~/.zshrc, ~/.profile, ~/.bash_profile, ~/.zprofile _CREDENTIAL_FILES — ~/.netrc, ~/.pgpass, ~/.npmrc, ~/.pypirc All 130 existing tests pass.
1 parent 3c59566 commit 69dd0f7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

tools/approval.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,20 @@ def get_current_session_key(default: str = "default") -> str:
9494
)
9595
_PROJECT_ENV_PATH = r'(?:(?:/|\.{1,2}/)?(?:[^\s/"\'`]+/)*\.env(?:\.[^/\s"\'`]+)*)'
9696
_PROJECT_CONFIG_PATH = r'(?:(?:/|\.{1,2}/)?(?:[^\s/"\'`]+/)*config\.yaml)'
97+
_SHELL_RC_FILES = (
98+
r'(?:~|\$home|\$\{home\})/\.'
99+
r'(?:bashrc|zshrc|profile|bash_profile|zprofile)\b'
100+
)
101+
_CREDENTIAL_FILES = (
102+
r'(?:~|\$home|\$\{home\})/\.'
103+
r'(?:netrc|pgpass|npmrc|pypirc)\b'
104+
)
97105
_SENSITIVE_WRITE_TARGET = (
98106
r'(?:/etc/|/dev/sd|'
99107
rf'{_SSH_SENSITIVE_PATH}|'
100-
rf'{_HERMES_ENV_PATH})'
108+
rf'{_HERMES_ENV_PATH}|'
109+
rf'{_SHELL_RC_FILES}|'
110+
rf'{_CREDENTIAL_FILES})'
101111
)
102112
_PROJECT_SENSITIVE_WRITE_TARGET = rf'(?:{_PROJECT_ENV_PATH}|{_PROJECT_CONFIG_PATH})'
103113
_COMMAND_TAIL = r'(?:\s*(?:&&|\|\||;).*)?$'

0 commit comments

Comments
 (0)