feat(security): deny writes to startup and global git config
Block write tool edits to secondary shell startup files and global git config paths while preserving project-local `.git/config` writes.
This commit is contained in:
parent
16fb573bae
commit
e2d80b6885
@ -51,6 +51,10 @@ def build_write_denied_paths(home: str) -> set[str]:
|
||||
os.path.join(home, ".profile"),
|
||||
os.path.join(home, ".bash_profile"),
|
||||
os.path.join(home, ".zprofile"),
|
||||
os.path.join(home, ".zshenv"),
|
||||
os.path.join(home, ".zlogin"),
|
||||
os.path.join(home, ".bash_login"),
|
||||
os.path.join(home, ".gitconfig"),
|
||||
os.path.join(home, ".netrc"),
|
||||
os.path.join(home, ".pgpass"),
|
||||
os.path.join(home, ".npmrc"),
|
||||
@ -78,6 +82,7 @@ def build_write_denied_prefixes(home: str) -> list[str]:
|
||||
os.path.join(home, ".azure"),
|
||||
os.path.join(home, ".config", "gh"),
|
||||
os.path.join(home, ".config", "gcloud"),
|
||||
os.path.join(home, ".config", "git"),
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@ -69,9 +69,24 @@ class TestWriteDenyExactPaths:
|
||||
|
||||
def test_shell_profiles(self):
|
||||
home = str(Path.home())
|
||||
for name in [".bashrc", ".zshrc", ".profile", ".bash_profile", ".zprofile"]:
|
||||
for name in [
|
||||
".bashrc", ".zshrc", ".profile", ".bash_profile", ".zprofile",
|
||||
".zshenv", ".zlogin", ".bash_login",
|
||||
]:
|
||||
assert _is_write_denied(os.path.join(home, name)) is True, f"{name} should be denied"
|
||||
|
||||
def test_global_git_config_paths(self):
|
||||
home = str(Path.home())
|
||||
for path in [
|
||||
os.path.join(home, ".gitconfig"),
|
||||
os.path.join(home, ".config", "git", "config"),
|
||||
os.path.join(home, ".config", "git", "hooks", "pre-commit"),
|
||||
]:
|
||||
assert _is_write_denied(path) is True, f"{path} should be denied"
|
||||
|
||||
def test_project_git_config_allowed(self):
|
||||
assert _is_write_denied("/tmp/someproject/.git/config") is False
|
||||
|
||||
def test_package_manager_configs(self):
|
||||
home = str(Path.home())
|
||||
for name in [".npmrc", ".pypirc", ".pgpass"]:
|
||||
|
||||
@ -252,7 +252,7 @@ THREAT_PATTERNS = [
|
||||
(r'\bcrontab\b',
|
||||
"persistence_cron", "medium", "persistence",
|
||||
"modifies cron jobs"),
|
||||
(r'\.(bashrc|zshrc|profile|bash_profile|bash_login|zprofile|zlogin)\b',
|
||||
(r'\.(bashrc|zshrc|zshenv|profile|bash_profile|bash_login|zprofile|zlogin)\b',
|
||||
"shell_rc_mod", "medium", "persistence",
|
||||
"references shell startup file"),
|
||||
(r'authorized_keys',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user