Compare commits

...

1 Commits

Author SHA1 Message Date
Teknium
e2d80b6885 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.
2026-06-13 06:52:11 -07:00
3 changed files with 22 additions and 2 deletions

View File

@@ -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"),
]
]

View File

@@ -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"]:

View File

@@ -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',