The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills-guard): stop shell_rc_mod matching attribute access
chenxue63395922bf7d
diff --git a/tests/tools/test_skills_guard.py b/tests/tools/test_skills_guard.pyindex 1fcafc45386..facfc537656 100644--- a/tests/tools/test_skills_guard.py+++ b/tests/tools/test_skills_guard.py@@ -536,6 +536,35 @@ class TestFalsePositiveReductions:bad.write_text(cmd + "\n", encoding="utf-8")assert any(fi.pattern_id == "dns_exfil" for fi in scan_file(bad, "leak.sh")), cmd+ def test_shell_rc_pattern_ignores_attribute_access(self, tmp_path):+ # ``.profile`` is both a shell startup file and the way every language+ # spells attribute access. Ordinary code produced one medium finding+ # per line, burying the findings a reviewer needs to read.+ code = tmp_path / "provider.py"+ code.write_text(+ "self.profile = load_plugin()\n"+ "assert self.profile.name == 'x'\n"+ "return user.profile\n"+ )+ assert not [+ fi for fi in scan_file(code, "provider.py")+ if fi.pattern_id == "shell_rc_mod"+ ]++ # Real references, in the forms they actually appear in, still flag.+ sh = tmp_path / "setup.sh"+ sh.write_text(+ "echo 'export X=1' >> ~/.profile\n"+ 'cp "$HOME/.profile" /tmp/p\n'+ "source ./.profile\n"+ "cat ~/.zshrc ~/.bash_profile\n"+ )+ flagged = {+ fi.line for fi in scan_file(sh, "setup.sh")+ if fi.pattern_id == "shell_rc_mod"+ }+ assert flagged == {1, 2, 3, 4}+# ---------------------------------------------------------------------------# .skillignore / .clawhubignore supportdiff --git a/tools/skills_guard.py b/tools/skills_guard.pyindex 5e3180f56f6..2f4c21e5513 100644--- a/tools/skills_guard.py+++ b/tools/skills_guard.py@@ -210,7 +210,14 @@ THREAT_PATTERNS = [(r'truncate\s+-s\s*0\s+/', "truncate_system", "critical", "destructive", "truncates system file to zero bytes"),# ── Persistence ──(r'\bcrontab\b', "persistence_cron", "medium", "persistence", "modifies cron jobs"),- (r'\.(bashrc|zshrc|profile|bash_profile|bash_login|zprofile|zlogin)\b',+ # ``profile`` is split out and anchored: ``.zshrc`` after a dot is always the file, but+ # ``.profile`` is also how every language spells attribute access (``self.profile``,+ # ``data?.profile``, ``func().profile``), which flooded scans of ordinary code. Requiring+ # a non-identifier, non-call/index/optional-chain character before the dot keeps real paths+ # (``~/.profile``, ``"$HOME/.profile"``, ``./.profile``) and drops attribute reads.+ (r'\.(bashrc|zshrc|bash_profile|bash_login|zprofile|zlogin)\b',+ "shell_rc_mod", "medium", "persistence", "references shell startup file"),+ (r'(?<![\w)\]?])\.profile\b',"shell_rc_mod", "medium", "persistence", "references shell startup file"),(r'authorized_keys', "ssh_backdoor", "critical", "persistence", "modifies SSH authorized keys"),(r'ssh-keygen', "ssh_keygen", "medium", "persistence", "generates SSH keys"),