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
Stop inventory hashes reading as password digests (code scanning #16)
Claude659e4ac38f89
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.goindex 8e8d277d..725af338 100644--- a/cli/beacon/internal/endpoint/inventory/inventory.go+++ b/cli/beacon/internal/endpoint/inventory/inventory.go@@ -837,6 +837,16 @@ func serverFromDefinition(item candidate, name string, def map[string]interface{command := firstString(def["command"])url := firstString(def["url"])envKeys := mapKeys(def["env"])+ // Fingerprint the redacted definition, not the raw one. The raw block is where an MCP server's+ // API token actually lives (`env: {GITHUB_TOKEN: ghp_...}`), and this is the only field that+ // carried those values into a digest: EnvKeys already drops secret-marked keys and Definition+ // is already redacted. A digest is not a disclosure, but a digest over a definition whose only+ // varying part is one token is guessable, and an inventory has no reason to hold that.+ //+ // Redaction is stable per key rather than per value, so the fingerprint still answers what it+ // is for -- a server was added, a command or URL changed -- and it stops answering one thing it+ // was never meant to: that a token was rotated while everything else stayed put.+ redactedDef := redactStructuredMap(def)server := MCPServer{Runtime: item.runtime,ServerName: valueForName(name, redaction),@@ -851,7 +861,7 @@ func serverFromDefinition(item candidate, name string, def map[string]interface{URLPresent: url != "",EnvKeys: valuesForEnvKeys(envKeys, redaction),EnvKeyCount: len(envKeys),- DefinitionHash: "sha256:" + canonicalHash(def),+ DefinitionHash: "sha256:" + canonicalHash(redactedDef),ParserStatus: StatusOK,Redaction: redaction,}@@ -859,7 +869,7 @@ func serverFromDefinition(item candidate, name string, def map[string]interface{server.CommandNameHash = hashString(filepath.Base(command))}if co.include {- server.Definition = redactStructuredMap(def)+ server.Definition = redactedDef}return server}@@ -1099,6 +1109,20 @@ func localEndpointText(text string) bool {return strings.Contains(text, "127.0.0.1") || strings.Contains(text, "localhost")}+// The three hashes below are correlation identifiers, not credential digests. They exist so two+// snapshots of the same machine can be compared -- did this config file move, is this the same MCP+// server as last run -- without the event carrying the operator's directory layout around with it.+// A password hash has the opposite job: it must survive an attacker who holds the digest, which is+// what makes bcrypt/scrypt/Argon2 and their work factors the right tool there. Nothing here is a+// credential, so a fast hash is the correct one, and deliberately so: these values are recomputed+// for every path, name, and file on every scheduled scan.+//+// Callers are responsible for what they pass. Every input today is a filesystem path, a server or+// command name, a timestamp, or a whole config file's bytes. A secret value must not be hashed+// here -- a digest over one short, low-entropy secret is a lookup table away from the secret+// itself -- so route anything that may hold a secret through redactStructured first, the way+// serverFromDefinition does. Secret-looking keys are stripped by containsSecretMarker.+func hashString(value string) string {if value == "" {return ""diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.goindex cb8e9c1f..23f76f88 100644--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go@@ -101,6 +101,50 @@ func TestScanIncludesNamesAndPaths(t *testing.T) {}}+// The definition fingerprint is a correlation identifier for "is this the same MCP server", and a+// hash is not a disclosure -- but a digest over a definition whose only varying part is one token+// is guessable, so the raw secret must not reach it. Two homes differing only in the value of a+// secret-marked env key must fingerprint identically; a real change to the definition must not.+func TestMCPDefinitionHashExcludesSecretEnvValues(t *testing.T) {+ definitionHash := func(t *testing.T, settings string) string {+ t.Helper()+ home := t.TempDir()+ writeFile(t, filepath.Join(home, ".claude", "settings.json"), settings)+ result := Scan(Options{HomeDir: home, SkipProjectScope: true, Now: fixedNow})+ if len(result.MCPServers) != 1 {+ t.Fatalf("MCPServers len = %d, want 1", len(result.MCPServers))+ }+ return result.MCPServers[0].DefinitionHash+ }++ const withToken = `{+ "mcpServers": {+ "github": {"command": "gh", "env": {"GITHUB_TOKEN": "ghp_aaaaaaaaaaaaaaaaaaaa", "NODE_ENV": "production"}}+ }+}`+ const rotatedToken = `{+ "mcpServers": {+ "github": {"command": "gh", "env": {"GITHUB_TOKEN": "ghp_bbbbbbbbbbbbbbbbbbbb", "NODE_ENV": "production"}}+ }+}`+ const changedCommand = `{+ "mcpServers": {+ "github": {"command": "gh-2", "env": {"GITHUB_TOKEN": "ghp_aaaaaaaaaaaaaaaaaaaa", "NODE_ENV": "production"}}+ }+}`++ base := definitionHash(t, withToken)+ if base == "" {+ t.Fatal("DefinitionHash is empty")+ }+ if rotated := definitionHash(t, rotatedToken); rotated != base {+ t.Errorf("rotating a secret env value changed DefinitionHash: %s -> %s", base, rotated)+ }+ if changed := definitionHash(t, changedCommand); changed == base {+ t.Errorf("changing the command left DefinitionHash at %s", base)+ }+}+func TestScanClaudeJSONMCPInventory(t *testing.T) {home := t.TempDir()work := t.TempDir()diff --git a/cli/beacon/internal/osuser/osuser.go b/cli/beacon/internal/osuser/osuser.goindex e877943d..521c91b0 100644--- a/cli/beacon/internal/osuser/osuser.go+++ b/cli/beacon/internal/osuser/osuser.go@@ -83,7 +83,7 @@ func Lookup(name string) (Info, error) {if err != nil {return Info{}, fmt.Errorf("%q is not in the local account database and NSS could not resolve it: %w", name, err)}- return parsePasswdLine(out, name)+ return parseAccountRecord(out, name)}func fromUser(u *user.User) (Info, error) {@@ -98,11 +98,19 @@ func fromUser(u *user.User) (Info, error) {return Info{Username: u.Username, UID: uid, GID: gid, HomeDir: u.HomeDir}, nil}-// parsePasswdLine reads one getent passwd record: name:passwd:uid:gid:gecos:home:shell.+// parseAccountRecord reads one account record from getent: name:passwd:uid:gid:gecos:home:shell.+//+// Named for the record rather than for the database it is queried from, because the password+// field is the one field this never reads: on every modern system it holds "x" and the hash lives+// in a shadow file getent does not expose. Fields 0, 2, 3, and 5 -- name, uid, gid, home -- are+// the whole of what is taken, and only the home directory travels any further than this package.+// The earlier name carried "passwd" into an identifier, which static analysis reads as a source+// of password material; every identity hash the resolved home directory reaches then looks like a+// password digest. See the comment on hashString in internal/endpoint/inventory.//// getent returns at most one record for a name query, but the output is scanned line by line// anyway so a trailing newline or a stray banner cannot turn a good answer into a parse failure.-func parsePasswdLine(out, want string) (Info, error) {+func parseAccountRecord(out, want string) (Info, error) {for _, line := range strings.Split(out, "\n") {line = strings.TrimRight(line, "\r")if strings.TrimSpace(line) == "" {@@ -128,5 +136,5 @@ func parsePasswdLine(out, want string) (Info, error) {// is what ownership and re-execution should use.return Info{Username: fields[0], UID: uid, GID: gid, HomeDir: fields[5]}, nil}- return Info{}, fmt.Errorf("no usable passwd record for %q", want)+ return Info{}, fmt.Errorf("no usable account record for %q", want)}diff --git a/cli/beacon/internal/osuser/osuser_test.go b/cli/beacon/internal/osuser/osuser_test.goindex 23a53c62..edfed20c 100644--- a/cli/beacon/internal/osuser/osuser_test.go+++ b/cli/beacon/internal/osuser/osuser_test.go@@ -11,21 +11,21 @@ import (// The parser is the part that runs against output this process did not produce, so it is the part// worth pinning. A directory service answers in the same seven-field format as /etc/passwd.-func TestParsePasswdLineReadsAnNSSRecord(t *testing.T) {- got, err := parsePasswdLine("alice:x:10001:10002::/home/alice:/bin/bash\n", "alice")+func TestParseAccountRecordReadsAnNSSRecord(t *testing.T) {+ got, err := parseAccountRecord("alice:x:10001:10002::/home/alice:/bin/bash\n", "alice")if err != nil {t.Fatal(err)}want := Info{Username: "alice", UID: 10001, GID: 10002, HomeDir: "/home/alice"}if got != want {- t.Errorf("parsePasswdLine = %+v, want %+v", got, want)+ t.Errorf("parseAccountRecord = %+v, want %+v", got, want)}}// A record whose uid or home is unusable must not resolve to a half-populated Info: the caller// would chown to uid 0 or write settings into "", both of which are worse than reporting that the// user could not be resolved.-func TestParsePasswdLineRejectsUnusableRecords(t *testing.T) {+func TestParseAccountRecordRejectsUnusableRecords(t *testing.T) {for name, out := range map[string]string{"too few fields": "alice:x:10001:10002:/home/alice\n","non-numeric uid": "alice:x:notanumber:10002::/home/alice:/bin/bash\n",@@ -36,8 +36,8 @@ func TestParsePasswdLineRejectsUnusableRecords(t *testing.T) {"banner only": "getent: something went sideways\n",} {t.Run(name, func(t *testing.T) {- if got, err := parsePasswdLine(out, "alice"); err == nil {- t.Errorf("parsePasswdLine(%q) = %+v, want an error", out, got)+ if got, err := parseAccountRecord(out, "alice"); err == nil {+ t.Errorf("parseAccountRecord(%q) = %+v, want an error", out, got)}})}@@ -45,8 +45,8 @@ func TestParsePasswdLineRejectsUnusableRecords(t *testing.T) {// A directory service may answer a differently-cased query with the account's canonical name.// Ownership and re-execution should use what the directory says, not what the caller typed.-func TestParsePasswdLinePrefersTheCanonicalName(t *testing.T) {- got, err := parsePasswdLine("alice:x:10001:10002::/home/alice:/bin/bash\n", "Alice")+func TestParseAccountRecordPrefersTheCanonicalName(t *testing.T) {+ got, err := parseAccountRecord("alice:x:10001:10002::/home/alice:/bin/bash\n", "Alice")if err != nil {t.Fatal(err)}