Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(redact): drop home-directory masking from Text (#7772)
Bohan Jiang88e9170dc142
diff --git a/server/pkg/agent/cursor_execute_unix_test.go b/server/pkg/agent/cursor_execute_unix_test.goindex a960a4b5e1..538bb9db5d 100644--- a/server/pkg/agent/cursor_execute_unix_test.go+++ b/server/pkg/agent/cursor_execute_unix_test.go@@ -148,10 +148,14 @@ exit 1t.Errorf("error = %q, want substring %q", result.Error, want)}}- for _, secret := range []string{"cursor-secret-token-value", homeDir} {- if strings.Contains(result.Error, secret) {- t.Errorf("error leaked %q: %q", secret, result.Error)- }+ if strings.Contains(result.Error, "cursor-secret-token-value") {+ t.Errorf("error leaked the bearer token: %q", result.Error)+ }+ // Host paths are deliberately NOT masked: a crash diagnostic is only+ // actionable if the path it names is the real one, and masking a path+ // segment never was an access-control boundary. See redact.Text.+ if !strings.Contains(result.Error, homeDir+"/private") {+ t.Errorf("error = %q, want the home path preserved verbatim", result.Error)}if result.Output != "" {t.Fatalf("output = %q, want empty failed output", result.Output)diff --git a/server/pkg/agent/stderr_tail.go b/server/pkg/agent/stderr_tail.goindex 25bb1ddfec..07fb2595d6 100644--- a/server/pkg/agent/stderr_tail.go+++ b/server/pkg/agent/stderr_tail.go@@ -22,10 +22,11 @@ var (agentDiagnosticSecretRe = regexp.MustCompile(`(?i)(authorization|auth|api[_-]?key|token|secret|password)(\s*[:=]\s*)([^\s,;]+)`))-// sanitizeAgentDiagnostic removes terminal control characters, common secret-// shapes, and local home-directory details before a child-process diagnostic is-// persisted in Result.Error. stderr is still forwarded to the local daemon log;-// this helper protects the task row and user-visible failure comment.+// sanitizeAgentDiagnostic removes terminal control characters and common secret+// shapes before a child-process diagnostic is persisted in Result.Error. stderr+// is still forwarded to the local daemon log; this helper protects the task row+// and user-visible failure comment. Local paths are left intact — they are what+// makes a crash diagnostic actionable, and hiding them was never a boundary.func sanitizeAgentDiagnostic(value string) string {value = strings.Map(func(r rune) rune {if r < 0x20 && r != '\n' && r != '\t' {diff --git a/server/pkg/redact/redact.go b/server/pkg/redact/redact.goindex 934ac721aa..77ac2c8eac 100644--- a/server/pkg/redact/redact.go+++ b/server/pkg/redact/redact.go@@ -3,10 +3,7 @@package redactimport (- "os"- "os/user""regexp"- "strings")// secretPattern pairs a compiled regex with its replacement text.@@ -152,30 +149,21 @@ func redactValue(v any, depth int) any {}}-// homeDir is resolved once at init for path redaction.-var homeDir string-var username string--func init() {- homeDir, _ = os.UserHomeDir()- if u, err := user.Current(); err == nil {- username = u.Username- }-}-// Text scans the input string for known secret patterns and replaces-// matches with safe placeholders. It also masks the local user's home-// directory path to prevent leaking the username.+// matches with safe placeholders.+//+// It deliberately does NOT mask the local home directory. That masking used to+// live here, but it was never a boundary: anyone who can read a transcript+// already sees repository paths, file contents, commands and diffs, so hiding+// one path segment protected nothing while making paths unusable for copy-paste+// and debugging. It was also incoherent about whose home directory it hid —+// Content/Output are redacted in the server's ingest handler, so a hosted+// deployment matched them against the *server's* home, never the machine+// running the agent. Transcript visibility is an authorization concern and is+// handled at that layer, not by string replacement here.func Text(s string) string {for _, p := range patterns {s = p.re.ReplaceAllString(s, p.replacement)}-- // Redact home directory paths (e.g. /Users/john/ → /Users/****/).- if homeDir != "" && username != "" {- masked := strings.Replace(homeDir, username, "****", 1)- s = strings.ReplaceAll(s, homeDir, masked)- }-return s}diff --git a/server/pkg/redact/redact_test.go b/server/pkg/redact/redact_test.goindex d0e950c575..f65bed66c1 100644--- a/server/pkg/redact/redact_test.go+++ b/server/pkg/redact/redact_test.go@@ -3,7 +3,6 @@ package redactimport ("encoding/json""os"- "os/user""strings""testing")@@ -197,21 +196,6 @@ func TestRedactGenericCredentials(t *testing.T) {}}-func TestRedactHomeDirectory(t *testing.T) {- t.Parallel()- if homeDir == "" || username == "" {- t.Skip("cannot determine home dir or username")- }- input := "Reading file at " + homeDir + "/Documents/secret.txt"- got := Text(input)- if strings.Contains(got, username) {- t.Fatalf("home directory username not redacted: %s", got)- }- if !strings.Contains(got, "****") {- t.Fatalf("expected **** in path, got: %s", got)- }-}-func TestNoFalsePositivesOnNormalText(t *testing.T) {t.Parallel()inputs := []string{@@ -362,27 +346,26 @@ func TestInputMapRedactsDeeplyNestedMaps(t *testing.T) {}}-func TestInputMapRedactsNestedHomePath(t *testing.T) {+// Home directory paths are intentionally left intact — see Text's doc comment.+// This guards the removal: a path under $HOME must survive verbatim, so nobody+// reintroduces host-path masking as an incidental side effect of another fix.+func TestTextLeavesHomePathIntact(t *testing.T) {t.Parallel()home, err := os.UserHomeDir()if err != nil || home == "" {t.Skip("no home directory resolved in this environment")}- u, err := user.Current()- if err != nil || u.Username == "" {- t.Skip("no current user resolved in this environment")- }- m := map[string]any{- "changes": []any{- map[string]any{"path": home + "/secret/app.go"},- },+ path := home + "/secret/app.go"++ if got := Text(path); got != path {+ t.Fatalf("home path was rewritten:\n input: %s\n output: %s", path, got)}- got := InputMap(m)- changes, _ := got["changes"].([]any)++ m := map[string]any{"changes": []any{map[string]any{"path": path}}}+ changes, _ := InputMap(m)["changes"].([]any)first, _ := changes[0].(map[string]any)- path, _ := first["path"].(string)- if strings.Contains(path, u.Username) {- t.Fatalf("username leaked from nested path: %s", path)+ if got, _ := first["path"].(string); got != path {+ t.Fatalf("nested home path was rewritten:\n input: %s\n output: %s", path, got)}}