Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(redact): mask Multica tokens in agent output (#11143)

张恕征b385c8c5e12a
diff --git a/packages/core/security/redact-secrets.test.ts b/packages/core/security/redact-secrets.test.ts
index 0d5ff8e718..6295bd18ff 100644
--- a/packages/core/security/redact-secrets.test.ts
+++ b/packages/core/security/redact-secrets.test.ts
@@ -3,6 +3,8 @@ import { describe, it, expect } from "vitest";
import { redactSecrets } from "./redact-secrets";
describe("redactSecrets", () => {
+ const multicaTokenBody = "0123456789abcdef".repeat(2) + "01234567";
+
it("redacts AWS access key", () => {
const result = redactSecrets("key: AKIAIOSFODNN7EXAMPLE");
expect(result).not.toContain("AKIAIOSFODNN7EXAMPLE");
@@ -53,6 +55,28 @@ describe("redactSecrets", () => {
expect(result).toContain("[REDACTED GITLAB TOKEN]");
});
+ it.each(["mat_", "mul_", "mdt_", "mcn_"])("redacts %s credentials in stored output", (prefix) => {
+ const token = prefix + multicaTokenBody;
+ expect(redactSecrets(`retrying with --token ${token} and moving on`))
+ .toBe("retrying with --token [REDACTED_MULTICA_TOKEN] and moving on");
+ });
+
+ it("redacts Multica credentials after escaped JSON whitespace", () => {
+ const token = "mat_" + multicaTokenBody;
+ expect(redactSecrets(JSON.stringify({ value: `line1\n${token}\t${token}` })))
+ .toBe(JSON.stringify({ value: "line1\n[REDACTED_MULTICA_TOKEN]\t[REDACTED_MULTICA_TOKEN]" }));
+ });
+
+ it("preserves the generic credential marker for Multica environment assignments", () => {
+ expect(redactSecrets("MULTICA_TOKEN=mat_" + multicaTokenBody))
+ .toBe("MULTICA_[REDACTED CREDENTIAL]");
+ });
+
+ it("preserves incomplete Multica credentials and identifiers containing a token prefix", () => {
+ const input = "mat_" + multicaTokenBody.slice(1) + " prefix_mat_" + multicaTokenBody;
+ expect(redactSecrets(input)).toBe(input);
+ });
+
it("redacts OpenAI/Anthropic API keys", () => {
const result = redactSecrets("sk-proj-abc123def456ghi789jkl012mno345");
expect(result).not.toContain("sk-proj");
diff --git a/packages/core/security/redact-secrets.ts b/packages/core/security/redact-secrets.ts
index 0011f45291..8a92911ea5 100644
--- a/packages/core/security/redact-secrets.ts
+++ b/packages/core/security/redact-secrets.ts
@@ -18,6 +18,8 @@ const patterns: { re: RegExp; replacement: string }[] = [
{ re: /\bAIza[0-9A-Za-z_-]{35}([^0-9A-Za-z_-]|$)/g, replacement: "[REDACTED GOOGLE API KEY]$1" },
// GitLab personal access tokens
{ re: /\bglpat-[A-Za-z0-9_-]{20,}\b/g, replacement: "[REDACTED GITLAB TOKEN]" },
+ // Match the server's Multica token rule and preserve short JSON control escapes.
+ { re: /(?:\b|(\\[bfnrt]))(?:mat|mul|mdt|mcn)_[0-9a-fA-F]{40}\b/g, replacement: "$1[REDACTED_MULTICA_TOKEN]" },
// OpenAI / Anthropic API keys
{ re: /\bsk-[A-Za-z0-9_-]{20,}\b/g, replacement: "[REDACTED API KEY]" },
// Slack tokens
diff --git a/server/pkg/redact/redact.go b/server/pkg/redact/redact.go
index 77ac2c8eac..096a27ba4f 100644
--- a/server/pkg/redact/redact.go
+++ b/server/pkg/redact/redact.go
@@ -47,6 +47,12 @@ var patterns = []secretPattern{
// GitLab personal access tokens
{regexp.MustCompile(`\bglpat-[A-Za-z0-9_-]{20,}\b`), "[REDACTED GITLAB TOKEN]"},
+ // Multica user PATs, daemon tokens, task tokens, and cloud-node PATs.
+ // Preserve short JSON control escapes that act as token separators.
+ // The space-free placeholder lets the generic TOKEN= rule below
+ // replace it in one piece.
+ {regexp.MustCompile(`(?:\b|(\\[bfnrt]))(?:mat|mul|mdt|mcn)_[0-9a-fA-F]{40}\b`), "${1}[REDACTED_MULTICA_TOKEN]"},
+
// Google API keys always start with the AIza prefix and are 39 chars total
// (AIza + 35). Capture and restore the trailing delimiter so keys ending in
// a non-word character such as '-' are still redacted.
diff --git a/server/pkg/redact/redact_test.go b/server/pkg/redact/redact_test.go
index f65bed66c1..ec3d6a6375 100644
--- a/server/pkg/redact/redact_test.go
+++ b/server/pkg/redact/redact_test.go
@@ -222,6 +222,83 @@ func TestRedactGitLabToken(t *testing.T) {
}
}
+// TestRedactMulticaTokens guards the mat_/mul_/mdt_/mcn_ credentials minted
+// by auth.GeneratePATToken and siblings (prefix + 40 hex characters). The
+// generic TOKEN=/Bearer rules only cover some surrounding syntax, so a bare
+// token in a CLI flag, error string, or JSON field used to reach the
+// database and WebSocket broadcast unredacted.
+func TestRedactMulticaTokens(t *testing.T) {
+ t.Parallel()
+ const hex40 = "0123456789abcdef0123456789abcdef01234567"
+ prefixes := []string{"mat_", "mul_", "mdt_", "mcn_"}
+ for _, prefix := range prefixes {
+ token := asm(prefix, hex40)
+ got := Text("retrying with --token " + token + " and moving on")
+ if strings.Contains(got, token) || strings.Contains(got, hex40) {
+ t.Fatalf("%s token not redacted: %s", prefix, got)
+ }
+ if got != "retrying with --token [REDACTED_MULTICA_TOKEN] and moving on" {
+ t.Fatalf("%s: surrounding text not preserved: %s", prefix, got)
+ }
+ }
+
+ // Nested JSON values are walked by InputMap through Text; a bare
+ // auth_token field must be masked the same way as a CLI flag.
+ token := asm("mat_", hex40)
+ got := InputMap(map[string]any{
+ "auth_token": token,
+ "args": []any{"--token", token},
+ })
+ if got["auth_token"] != "[REDACTED_MULTICA_TOKEN]" {
+ t.Fatalf("InputMap auth_token = %#v, want the Multica placeholder", got["auth_token"])
+ }
+ args, ok := got["args"].([]any)
+ if !ok || len(args) != 2 || args[1] != "[REDACTED_MULTICA_TOKEN]" {
+ t.Fatalf("InputMap args = %#v, want the flag value redacted", got["args"])
+ }
+
+ // Wrong length, leftover test-style prefixes, and ordinary words that
+ // only share a letter prefix must stay untouched.
+ untouched := []string{
+ asm("mat_", "0123456789abcdef0123456789abcdef0123456"), // 39 hex
+ asm("mat_", "0123456789abcdef0123456789abcdef012345678"), // 41 hex
+ "mat_self_mention_not_a_real_token",
+ "the matrix_0123456789abcdef0123456789abcdef01234567 id",
+ }
+ for _, input := range untouched {
+ if got := Text(input); got != input {
+ t.Fatalf("false positive redaction:\n input: %s\n output: %s", input, got)
+ }
+ }
+}
+
+func TestRedactMulticaTokenContext(t *testing.T) {
+ t.Parallel()
+
+ const hex40 = "0123456789abcdef0123456789abcdef01234567"
+ token := asm("mat_", hex40)
+ tests := []struct {
+ name string
+ input string
+ want string
+ }{
+ {"environment assignment", "MULTICA_TOKEN=" + token, "MULTICA_[REDACTED CREDENTIAL]"},
+ {
+ name: "escaped JSON",
+ input: `{"value":"line1\n` + token + `\t` + token + `"}`,
+ want: `{"value":"line1\n[REDACTED_MULTICA_TOKEN]\t[REDACTED_MULTICA_TOKEN]"}`,
+ },
+ {"embedded in an identifier", "prefix_" + token, "prefix_" + token},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := Text(tt.input); got != tt.want {
+ t.Errorf("Text() = %q, want %q", got, tt.want)
+ }
+ })
+ }
+}
+
func TestRedactJWT(t *testing.T) {
t.Parallel()
input := "token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"