The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Keep token type prefixes so credential rules still match the log
Claudeb599004d5f5d
diff --git a/docs/security/retention-redaction.mdx b/docs/security/retention-redaction.mdxindex 17539038..0bac8b85 100644--- a/docs/security/retention-redaction.mdx+++ b/docs/security/retention-redaction.mdx@@ -27,7 +27,7 @@ Redaction runs on retained text (prompts, command output, diffs, tool arguments| Authorization headers and flags | `Authorization: Bearer …`, `Authorization: Basic …`, `--password …`, `--token=…` || URL credentials | the password in `postgres://user:…@host`, `https://x-access-token:…@github.com` || Private keys | PEM and OpenSSH `PRIVATE KEY` blocks, including a block cut off before its end line |-| Recognizable tokens | Anthropic and OpenAI `sk-…`, AWS `AKIA…`/`ASIA…`, GitHub `ghp_…`/`github_pat_…`, GitLab `glpat-…`, Slack `xox…-`, Stripe `sk_live_…`, Google `AIza…`, npm, Hugging Face, Beacon `bcn_…` keys, and JWTs |+| Recognizable tokens (the public type prefix stays, as in `ghp_[REDACTED]`) | Anthropic and OpenAI `sk-…`, AWS `AKIA…`/`ASIA…`, GitHub `ghp_…`/`github_pat_…`, GitLab `glpat-…`, Slack `xox…-`, Stripe `sk_live_…`, Google `AIza…`, npm, Hugging Face, Beacon `bcn_…` keys, and JWTs |Redaction is pattern-based. A credential with no label and no recognizable shape, such as a bare random password, is not detected, so treat retained content as sensitive. Metadata-only forwarding is the control for keeping content off Beacon Cloud entirely.diff --git a/pkg/asymptoteobserve/privacy.go b/pkg/asymptoteobserve/privacy.goindex 9af5dde7..77840bd0 100644--- a/pkg/asymptoteobserve/privacy.go+++ b/pkg/asymptoteobserve/privacy.go@@ -35,35 +35,72 @@ const secretValue = "[^\"'`,\\s}\\]\\\\\\[][^\"'`,\\s}\\]\\\\]*"type secretRule struct {pattern *regexp.Regexpreplacement string+ // keep, when set, leaves a match alone if its value (${2}) passes.+ keep func(value string) bool+}++// isAuthScheme reports whether a labeled value is an Authorization scheme rather than a+// credential. `Authorization: Bearer x` is redacted to `Authorization: Bearer [REDACTED]` by the+// header rule, and the assignment rule must not then take `Bearer` for the value and erase what+// kind of credential the line held.+func isAuthScheme(value string) bool {+ switch strings.ToLower(value) {+ case "bearer", "basic", "token", "digest":+ return true+ }+ return false}var secretRules = []secretRule{// A private key block, or the rest of the text when the block was cut before its END line.- {regexp.MustCompile(`-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----(?:[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----|[\s\S]*$)`), redactedValue},+ {regexp.MustCompile(`-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----(?:[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----|[\s\S]*$)`), 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},- {regexp.MustCompile(`(?i)(\bbearer\s+)([a-z0-9._~+/=-]+)()`), "${1}" + redactedValue},+ {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},// 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.- {regexp.MustCompile(`(?i)(\b` + secretKeyName + secretAssignment + `)(` + secretValue + `)()`), "${1}" + redactedValue},+ {regexp.MustCompile(`(?i)(\b` + secretKeyName + secretAssignment + `)(` + secretValue + `)()`), "${1}" + redactedValue, isAuthScheme},// A command-line flag: `--password x`, `--token=x`, `--api-key x`.- {regexp.MustCompile(`(?i)((?:^|\s)--?[a-z0-9-]*(?:password|passwd|passphrase|token|secret|api-?key|access-?key)(?:=|\s+))([^\s"'-][^\s"']*)()`), "${1}" + redactedValue},+ {regexp.MustCompile(`(?i)((?:^|\s)--?[a-z0-9-]*(?:password|passwd|passphrase|token|secret|api-?key|access-?key)(?:=|\s+))([^\s"'-][^\s"']*)()`), "${1}" + redactedValue, nil},// The password in a URL's userinfo: `postgres://user:pw@host`, `https://x-access-token:[email protected]`.- {regexp.MustCompile(`(?i)(\b[a-z][a-z0-9+.-]*://[^/\s:@"'<>]+:)([^@/\s"'<>]+)(@)`), "${1}" + redactedValue + "${3}"},- // Credentials recognizable by their own shape, wherever they appear.- {regexp.MustCompile(`\bsk-[A-Za-z0-9_-]{20,}`), redactedValue}, // Anthropic sk-ant-, OpenAI sk-proj- and sk-- {regexp.MustCompile(`\b(?:AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}\b`), redactedValue}, // AWS access key id- {regexp.MustCompile(`\bgh[pousr]_[A-Za-z0-9]{30,}`), redactedValue}, // GitHub tokens- {regexp.MustCompile(`\bgithub_pat_[A-Za-z0-9_]{22,}`), redactedValue}, // GitHub fine-grained tokens- {regexp.MustCompile(`\bglpat-[A-Za-z0-9_-]{20,}`), redactedValue}, // GitLab- {regexp.MustCompile(`\bxox[abposr]-[A-Za-z0-9-]{10,}`), redactedValue}, // Slack- {regexp.MustCompile(`\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}`), redactedValue}, // Stripe- {regexp.MustCompile(`\bAIza[0-9A-Za-z_-]{35}`), redactedValue}, // Google API key- {regexp.MustCompile(`\bnpm_[A-Za-z0-9]{36}`), redactedValue}, // npm- {regexp.MustCompile(`\bhf_[A-Za-z0-9]{30,}`), redactedValue}, // Hugging Face- {regexp.MustCompile(`\bbcn_(?:api|device|mcp)_[A-Za-z0-9_-]{8,}`), redactedValue}, // Beacon's own keys- {regexp.MustCompile(`\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`), redactedValue}, // JWT+ {regexp.MustCompile(`(?i)(\b[a-z][a-z0-9+.-]*://[^/\s:@"'<>]+:)([^@/\s"'<>]+)(@)`), "${1}" + redactedValue + "${3}", nil},+ // Credentials recognizable by their own shape, wherever they appear. The type prefix is public+ // and stays (`ghp_[REDACTED]`, `AKIA[REDACTED]`), the way secret scanners report a finding: the+ // line still says a GitHub token or an AWS key was there, which is what detection rules match on+ // in the log, and none of the credential is left.+ {regexp.MustCompile(`\b(sk-)[A-Za-z0-9_-]{20,}`), "${1}" + redactedValue, nil}, // Anthropic sk-ant-, OpenAI sk-proj- and sk-+ {regexp.MustCompile(`\b(AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}\b`), "${1}" + redactedValue, nil}, // AWS access key id+ {regexp.MustCompile(`\b(gh[pousr]_)[A-Za-z0-9]{30,}`), "${1}" + redactedValue, nil}, // GitHub tokens+ {regexp.MustCompile(`\b(github_pat_)[A-Za-z0-9_]{22,}`), "${1}" + redactedValue, nil}, // GitHub fine-grained tokens+ {regexp.MustCompile(`\b(glpat-)[A-Za-z0-9_-]{20,}`), "${1}" + redactedValue, nil}, // GitLab+ {regexp.MustCompile(`\b(xox[abposr]-)[A-Za-z0-9-]{10,}`), "${1}" + redactedValue, nil}, // Slack+ {regexp.MustCompile(`\b([rs]k_(?:live|test)_)[A-Za-z0-9]{16,}`), "${1}" + redactedValue, nil}, // Stripe+ {regexp.MustCompile(`\b(AIza)[0-9A-Za-z_-]{35}`), "${1}" + redactedValue, nil}, // Google API key+ {regexp.MustCompile(`\b(npm_)[A-Za-z0-9]{36}`), "${1}" + redactedValue, nil}, // npm+ {regexp.MustCompile(`\b(hf_)[A-Za-z0-9]{30,}`), "${1}" + redactedValue, nil}, // Hugging Face+ {regexp.MustCompile(`\b(bcn_(?:api|device|mcp)_)[A-Za-z0-9_-]{8,}`), "${1}" + redactedValue, nil}, // Beacon's own keys+ {regexp.MustCompile(`\b(eyJ)[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`), "${1}" + redactedValue, nil}, // JWT+}++func (rule secretRule) apply(value string) string {+ if rule.keep == nil {+ return rule.pattern.ReplaceAllString(value, rule.replacement)+ }+ var out []byte+ last := 0+ for _, match := range rule.pattern.FindAllStringSubmatchIndex(value, -1) {+ if match[4] >= 0 && rule.keep(value[match[4]:match[5]]) {+ continue+ }+ out = append(out, value[last:match[0]]...)+ out = rule.pattern.ExpandString(out, rule.replacement, value, match)+ last = match[1]+ }+ if out == nil {+ return value+ }+ return string(append(out, value[last:]...))}// assignedSecretPattern captures the value of a labeled assignment so a bare copy of it elsewhere in@@ -92,7 +129,7 @@ func RedactString(value string) string {}}for _, rule := range secretRules {- value = rule.pattern.ReplaceAllString(value, rule.replacement)+ value = rule.apply(value)}// Each copy is searched for and removed; none of it survives into the result.for _, copied := range assigned {diff --git a/pkg/asymptoteobserve/privacy_test.go b/pkg/asymptoteobserve/privacy_test.goindex d276ace1..87b07c90 100644--- a/pkg/asymptoteobserve/privacy_test.go+++ b/pkg/asymptoteobserve/privacy_test.go@@ -173,6 +173,18 @@ func TestRedactStringKeepsLabelsAndOrdinaryText(t *testing.T) {if got := RedactString("git clone https://u:[email protected]/r"); got != "git clone https://u:[REDACTED]@example.com/r" {t.Fatalf("URL credential = %q, want the scheme, user and host kept", got)}+ // Detection rules match what kind of credential a line held, so the public type prefix and the+ // Authorization scheme stay.+ for input, want := range map[string]string{+ "deploy with ghp_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789": "deploy with ghp_[REDACTED]",+ "upload with AKIAIOSFODNN7EXAMPLE": "upload with AKIA[REDACTED]",+ "Authorization: Bearer abc.def.ghi": "Authorization: Bearer [REDACTED]",+ `{"authorization": "Basic dXNlcjpwYXNz"}`: `{"authorization": "Basic [REDACTED]"}`,+ } {+ if got := RedactString(input); got != want {+ t.Fatalf("RedactString(%q) = %q, want %q", input, got, want)+ }+ }}// Events are sanitized again on every read path, so a second pass must not change the first one'sdiff --git a/pkg/asymptoteobserve/threatrules/conformance_test.go b/pkg/asymptoteobserve/threatrules/conformance_test.goindex 7e50932a..989600e7 100644--- a/pkg/asymptoteobserve/threatrules/conformance_test.go+++ b/pkg/asymptoteobserve/threatrules/conformance_test.go@@ -6,6 +6,8 @@ import ("runtime""strings""testing"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve")// repoRoot locates the repository root by walking up from this test file until it finds@@ -66,6 +68,37 @@ func TestPackConformance(t *testing.T) {}}+// TestPackMatchesWhatTheLogHolds runs every fixture again after the sanitizer every log writer+// applies, and requires the same verdict. `beacon scan` and the dashboard only ever see the+// sanitized line, so a rule that matches a raw value redaction removes (a token, a key) is dead on+// real logs even though its plain fixtures pass.+func TestPackMatchesWhatTheLogHolds(t *testing.T) {+ rules, err := LoadDir(rulesDir(t))+ if err != nil {+ t.Fatalf("load rule pack: %v", err)+ }+ for _, rule := range rules {+ compiled, err := Compile(rule)+ if err != nil {+ t.Fatalf("rule %q: compile: %v", rule.ID, err)+ }+ for _, fixture := range rule.Tests {+ events := fixture.EventList()+ for i := range events {+ events[i] = asymptoteobserve.SanitizeEvent(events[i], 64*1024)+ }+ got, err := compiled.Evaluate(events)+ if err != nil {+ t.Errorf("%s/%s: evaluate sanitized events: %v", rule.ID, fixture.Name, err)+ continue+ }+ if got != fixture.Verdict {+ t.Errorf("%s/%s: verdict %q on the sanitized events the log holds, want %q", rule.ID, fixture.Name, got, fixture.Verdict)+ }+ }+ }+}+// TestPackSharedCredentialRead pins correlation read steps that are meant to reuse// credential-file-read's definition of a secret. The format has no include mechanism, so// the expression is copied; this fails when one copy changes without the other.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.yamlindex efae34d6..2ed35efc 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@@ -1,5 +1,5 @@id: handoff-to-second-agent-with-credentials-version: 1+version: 2title: Agent handed off to a second agent with credential-shaped payloaddescription: >A command.executed event spawns or invokes a second AI agent runtime@@ -13,7 +13,10 @@ description: >the command line. The second agent thus inherits the secret in itsinitial context, a classic LLM06/AML.T0024 exfiltration shape. Therule requires both the second-agent invocation AND the credential- reference to fire.+ 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.severity: criticalstatus: experimentalposture: detect@@ -27,7 +30,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,}|sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|xox[bpars]-[A-Za-z0-9-]{10,})")+ 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:@@ -62,6 +65,34 @@ tests:event: { action: command.executed }command: { command: "claude -p 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.payload.sig - hit /api'" }session: { id: s1 }+ - name: claude_with_github_token_literal+ verdict: match+ events:+ - timestamp: "2026-06-23T10:03:10Z"+ event: { action: command.executed }+ command: { command: "claude -p \"deploy with ghp_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789\"" }+ session: { id: s1 }+ - name: codex_with_aws_key_literal+ verdict: match+ events:+ - timestamp: "2026-06-23T10:03:20Z"+ event: { action: command.executed }+ command: { command: "codex exec 'upload with AKIAIOSFODNN7EXAMPLE'" }+ session: { id: s1 }+ - name: gemini_with_slack_and_openai_literals+ verdict: match+ events:+ - timestamp: "2026-06-23T10:03:30Z"+ event: { action: command.executed }+ command: { command: "gemini -p 'post with xoxb-1234567890-abcdefghijkl and sk-abcdefghijklmnopqrstuvwxyz0123'" }+ session: { id: s1 }+ - name: claude_with_redacted_github_token_in_log+ verdict: match+ events:+ - timestamp: "2026-06-23T10:03:40Z"+ event: { action: command.executed }+ command: { command: "claude -p \"deploy with ghp_[REDACTED]\"" }+ session: { id: s1 }- name: codex_with_kubeconfigverdict: matchevents: