Skip to content

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

Match only JWT bearers in the handoff rule's redacted form

Claudee19698f19e39
diff --git a/pkg/asymptoteobserve/privacy.go b/pkg/asymptoteobserve/privacy.go
index a7c71ed0..428d7c1d 100644
--- a/pkg/asymptoteobserve/privacy.go
+++ b/pkg/asymptoteobserve/privacy.go
@@ -87,6 +87,12 @@ func isAuthScheme(value string) bool {
return false
}
+// isRedactedJWTPrefix keeps the `eyJ` the header rule left in `Bearer eyJ[REDACTED]`, which the
+// bearer rule would otherwise take for a token of its own.
+func isRedactedJWTPrefix(value string) bool {
+ return value == "eyJ"
+}
+
// isLiteralOrAuthScheme is isAuthScheme, plus the JSON literals that carry no secret.
func isLiteralOrAuthScheme(value string) bool {
switch value {
@@ -102,9 +108,12 @@ var redactionRules = []redactionRule{
// block was cut) the rest of the text goes.
{regexp.MustCompile(`-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----(?:\s|\\[rn]|(?:Proc-Type|DEK-Info|Comment|Version):[^\n\\]*)*` +
`[A-Za-z0-9+/=]{16,}[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----|$)`), redactedValue, nil},
- // An Authorization header's credential after its scheme: Bearer, Basic, Token, Digest.
- {regexp.MustCompile(`(?i)(authorization["']?\s*[:=]\s*["']?(?:bearer|basic|token|digest)\s+)([^"'\s,]+)()`), "${1}" + redactedValue, nil},
- {regexp.MustCompile(`(?i)(\bbearer\s+)([a-z0-9._~+/=-]+)()`), "${1}" + redactedValue, nil},
+ // An Authorization header's credential after its scheme: Bearer, Basic, Token, Digest. A JWT
+ // keeps its public `eyJ` prefix, as the shape rules below keep theirs, so `Bearer eyJ[REDACTED]`
+ // still says a token was there where `Bearer [REDACTED]` may only have been the word "token" or
+ // a `$VARIABLE`.
+ {regexp.MustCompile(`(?i)(authorization["']?\s*[:=]\s*["']?(?:bearer|basic|token|digest)\s+(?-i:eyJ)?)([^"'\s,]+)()`), "${1}" + redactedValue, nil},
+ {regexp.MustCompile(`(?i)(\bbearer\s+(?-i:eyJ)?)(?P<value>[a-z0-9._~+/=-]+)`), "${1}" + redactedValue, isRedactedJWTPrefix},
// A labeled assignment in prose, shell, env files, YAML, TOML or JSON: `token=x`,
// `export GITHUB_TOKEN="x"`, `{"api_key": "x"}`. The closing quote of a quoted label is allowed
// between the label and the separator. A quoted value runs to its closing quote; the unquoted
@@ -144,7 +153,11 @@ func (rule redactionRule) apply(value string) string {
if rule.keep == nil {
return rule.pattern.ReplaceAllString(value, rule.replacement)
}
- group := 2 * rule.pattern.SubexpIndex("value")
+ index := rule.pattern.SubexpIndex("value")
+ if index < 0 {
+ index = 2
+ }
+ group := 2 * index
var out []byte
last := 0
for _, match := range rule.pattern.FindAllStringSubmatchIndex(value, -1) {
diff --git a/pkg/asymptoteobserve/privacy_test.go b/pkg/asymptoteobserve/privacy_test.go
index c52ad357..646e6faf 100644
--- a/pkg/asymptoteobserve/privacy_test.go
+++ b/pkg/asymptoteobserve/privacy_test.go
@@ -179,6 +179,8 @@ func TestRedactStringKeepsLabelsAndOrdinaryText(t *testing.T) {
"deploy with ghp_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789": "deploy with ghp_[REDACTED]",
"upload with AKIAIOSFODNN7EXAMPLE": "upload with AKIA[REDACTED]",
"Authorization: Bearer abc.def.ghi": "Authorization: Bearer [REDACTED]",
+ "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.e30.sig": "Authorization: Bearer eyJ[REDACTED]",
+ "curl -H 'Authorization: bearer eyJhbGciOiJ9.x.y'": "curl -H 'Authorization: bearer eyJ[REDACTED]'",
`{"authorization": "Basic dXNlcjpwYXNz"}`: `{"authorization": "Basic [REDACTED]"}`,
} {
if got := RedactString(input); got != want {
diff --git a/rules/agent-control/handoff-to-second-agent-with-credentials.rule.yaml b/rules/agent-control/handoff-to-second-agent-with-credentials.rule.yaml
index 2ed35efc..5fc74e6e 100644
--- a/rules/agent-control/handoff-to-second-agent-with-credentials.rule.yaml
+++ b/rules/agent-control/handoff-to-second-agent-with-credentials.rule.yaml
@@ -15,8 +15,10 @@ description: >
rule requires both the second-agent invocation AND the credential
reference to fire. Beacon redacts literal tokens before it writes the
log and keeps their type prefix (`ghp_[REDACTED]`, `AKIA[REDACTED]`,
- `Bearer [REDACTED]`), so the literal arm matches that form as well as
- the raw one.
+ `Bearer eyJ[REDACTED]`), so the literal arm matches that form as well
+ as the raw one. A bare `Bearer [REDACTED]` is not enough: the redactor
+ also writes it for prose ("bearer token auth") and `$VARIABLE`
+ references.
severity: critical
status: experimental
posture: detect
@@ -30,7 +32,7 @@ match: >
e.command.command.matches("(?i)(^|[;&|]|&&|\\|\\||\\bsudo\\s+|\\benv\\s+|\\bnpx\\s+)\\s*(claude|codex|cursor-agent|aider|goose|opencode|gemini|mcp[ -]?server)\\b") &&
(
e.command.command.matches("(?i)(\\.env($|[^a-z])|\\.aws/credentials|\\.aws/config|\\.ssh/id_(rsa|ed25519|ecdsa|dsa)([^a-z]|$)|\\.gnupg/private-keys-v1\\.d|secring\\.gpg|/\\.kube/config|\\.kdbx($|[^a-z])|\\.netrc($|[^a-z])|\\.pgpass($|[^a-z])|secrets\\.yaml)") ||
- e.command.command.matches("(?i)(Bearer\\s+(eyJ[A-Za-z0-9_-]{10,}|\\[REDACTED\\])|sk-([A-Za-z0-9]{20,}|\\[REDACTED\\])|ghp_([A-Za-z0-9]{20,}|\\[REDACTED\\])|AKIA([0-9A-Z]{16}|\\[REDACTED\\])|xox[bpars]-([A-Za-z0-9-]{10,}|\\[REDACTED\\]))")
+ e.command.command.matches("(?i)(Bearer\\s+eyJ([A-Za-z0-9_-]{10,}|\\[REDACTED\\])|sk-([A-Za-z0-9]{20,}|\\[REDACTED\\])|ghp_([A-Za-z0-9]{20,}|\\[REDACTED\\])|AKIA([0-9A-Z]{16}|\\[REDACTED\\])|xox[bpars]-([A-Za-z0-9-]{10,}|\\[REDACTED\\]))")
)
emit:
@@ -93,6 +95,20 @@ tests:
event: { action: command.executed }
command: { command: "claude -p \"deploy with ghp_[REDACTED]\"" }
session: { id: s1 }
+ - name: claude_prose_about_bearer_auth
+ verdict: no_match
+ events:
+ - timestamp: "2026-06-23T10:03:50Z"
+ event: { action: command.executed }
+ command: { command: "claude -p \"add bearer token auth to the API\"" }
+ session: { id: s1 }
+ - name: codex_with_bearer_env_reference
+ verdict: no_match
+ events:
+ - timestamp: "2026-06-23T10:03:55Z"
+ event: { action: command.executed }
+ command: { command: "codex exec \"curl -H 'Authorization: Bearer $GITHUB_TOKEN' https://api.github.com/user\"" }
+ session: { id: s1 }
- name: codex_with_kubeconfig
verdict: match
events: