Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix: redact complete configured MCP secrets in one pass

Afloat176917fd2896
diff --git a/server/mcp-probe.test.ts b/server/mcp-probe.test.ts
index 274f43b29a..5f5dc38fd7 100644
--- a/server/mcp-probe.test.ts
+++ b/server/mcp-probe.test.ts
@@ -560,4 +560,24 @@ describe("remote MCP probe", () => {
await fake.close();
}
});
+
+ it("redacts complete credentials when configured values contain one another", async () => {
+ const fake = await startFakeHttpMcp({ tools: [{
+ name: "read_prefix-sensitive-suffix",
+ description: "prefix-sensitive-suffix / prefix / a.b+c / acted",
+ inputSchema: { type: "object" },
+ }] });
+ try {
+ await expect(probeMcpServer({
+ type: "http", url: fake.url,
+ headers: { "X-Short": "prefix", "X-Long": "prefix-sensitive-suffix", "X-Symbols": "a.b+c", "X-Fragment": "acted" },
+ enabled: false,
+ }, 2_000)).resolves.toEqual({
+ ok: true,
+ tools: [{ name: "read_[redacted]", description: "[redacted] / [redacted] / [redacted] / [redacted]" }],
+ });
+ } finally {
+ await fake.close();
+ }
+ });
});
diff --git a/server/mcp-probe.ts b/server/mcp-probe.ts
index dd42c0bae3..d435977c9c 100644
--- a/server/mcp-probe.ts
+++ b/server/mcp-probe.ts
@@ -75,11 +75,10 @@ function publicProbeError(kind: "spawn" | "timeout" | "protocol" | "closed" | "c
}
function redactConfiguredValues(value: string, secrets: Record<string, string>): string {
- let redacted = value;
- for (const secret of Object.values(secrets)) {
- if (secret) redacted = redacted.split(secret).join("[redacted]");
- }
- return redacted;
+ const alternatives = [...new Set(Object.values(secrets))].filter(Boolean)
+ .sort((a, b) => b.length - a.length)
+ .map((secret) => secret.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
+ return alternatives.length ? value.replace(new RegExp(alternatives.join("|"), "g"), "[redacted]") : value;
}
/** Bounded and redacted: `secrets` are configured values a careless server might echo. */