Skip to content

feat(rules): persistence and supply chain detection#6

Open
MiguelHzBz wants to merge 2 commits intoleogr:mainfrom
MiguelHzBz:add-persistence-detection-rules
Open

feat(rules): persistence and supply chain detection#6
MiguelHzBz wants to merge 2 commits intoleogr:mainfrom
MiguelHzBz:add-persistence-detection-rules

Conversation

@MiguelHzBz
Copy link
Copy Markdown

Summary

Adds rules/user/persistence-detection.yaml with 6 rules covering extension vectors beyond MCP and skill files:

  • Deny hooks injection into Claude Code settings (CRITICAL): blocks writing a hooks block to settings.json — hooks run arbitrary commands before/after every tool call across all future sessions, outside the sandbox
  • Ask before MCP registration in settings.json (WARNING): closes the mcpServers key path in settings.json not covered by .mcp.json rules
  • Ask before git hooks write (WARNING): .git/hooks/ files persist for the lifetime of the repo clone and execute outside any sandbox on every git operation
  • Ask before package registry redirect (WARNING): .npmrc / .pypirc / pip.conf with registry redirect sends every subsequent install to an attacker-controlled index
  • Deny API base URL override in env file (CRITICAL): ANTHROPIC_BASE_URL / OPENAI_BASE_URL / OPENAI_API_BASE in .env files proxies all model traffic through an attacker-controlled endpoint
  • Ask before AI API key written to env file (WARNING): prevents accidental key commit to version control or staging for exfiltration

Test plan

  • bash tests/test_persistence_rules.sh — 40 test cases (40/40 verified), including a cross-rule escalation test where a single .env write triggers both the deny rule (base URL override) and the ask rule (API key), with deny winning
  • Requires Falco 0.43+ and the built plugin/interceptor. To replicate: provision an EC2 Ubuntu 22.04 instance, follow the build instructions in the README, then run the test script directly.

Adds rules/default/persistence-detection.yaml with 6 rules covering
extension vectors beyond MCP and skill files:

- Deny hooks injection into Claude Code settings (CRITICAL): blocks
  writing a hooks block to settings.json — hooks run arbitrary commands
  before/after every tool call across all future sessions.
- Ask before MCP registration in settings.json (WARNING): closes the
  alternative mcpServers registration path not covered by .mcp.json rules.
- Ask before git hooks write (WARNING): .git/hooks/ files persist for
  the lifetime of the repo clone and execute outside the sandbox.
- Ask before package registry redirect (WARNING): .npmrc/.pypirc/pip.conf
  redirects every subsequent install to an attacker-controlled index.
- Deny API base URL override in env file (CRITICAL): ANTHROPIC_BASE_URL /
  OPENAI_BASE_URL override proxies all model traffic through an attacker
  endpoint where prompts and responses can be read or modified.
- Ask before AI API key written to env file (WARNING): prevents accidental
  key commit to version control or staging for exfiltration.

Includes test_persistence_rules.sh with 40 test cases (40/40 verified).
@MiguelHzBz MiguelHzBz force-pushed the add-persistence-detection-rules branch from f0a8207 to b979268 Compare April 10, 2026 10:57
- Add .pnpmrc and .yarnrc.yml to is_registry_config_write (P3, P4)
- Add npmRegistryServer to is_registry_redirect_content for yarn v2 (P4)
- Add .env.staging, .env.test, .env.ci, .env.override to is_env_file_write (P5, P6)
- Add Rule 7: Ask before Bash command accessing .git/hooks/ path
  (P1: shell redirection bypasses Write/Edit-only Rule 3)
- Add Rule 8: Ask before Bash CLI registry redirect (npm config set, pip config set)
  (P2: CLI-level redirect never goes through Write/Edit tool path)
- Add test_persistence_bypass.sh covering all 6 bypass sections (~20 test cases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant