Skip to content

Commit 27c2377

Browse files
fix(provider): withhold credential-labelled ACP diagnostic lines
1 parent dad4b8c commit 27c2377

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

‎packages/provider-core/src/server/failure.test.ts‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ it("keeps structured ACP exit details through cause wrappers without reading arb
5656
assert.equal(failure.code, "23");
5757
assert.equal(
5858
failure.message,
59-
"ACP process exited with code 23\nSynthetic configuration failed.\napi_key=[REDACTED]",
59+
"ACP process exited with code 23\nSynthetic configuration failed.\n[REDACTED credential diagnostic]",
6060
);
6161
}
6262
assert.equal(
@@ -82,7 +82,8 @@ it("keeps structured ACP exit details through cause wrappers without reading arb
8282

8383
it("redacts prefixed credential fields and escaped quoted values in ACP stderr", () => {
8484
const stderr = [
85-
"Synthetic failure: MISTRAL_API_KEY=FixtureOnly0123456789abcdefABCDEF",
85+
"Synthetic configuration failed.",
86+
"MISTRAL_API_KEY=FixtureOnly0123456789abcdefABCDEF",
8687
"GEMINI_API_KEY=AIzaFixtureOnly0123456789",
8788
JSON.stringify({
8889
refresh_token: "fixture-refresh-value",
@@ -94,7 +95,7 @@ it("redacts prefixed credential fields and escaped quoted values in ACP stderr",
9495
const failure = makeProviderFailure({
9596
cause: { _tag: "AcpProcessExitedError", code: 23, stderr },
9697
});
97-
assert.include(failure.message, "Synthetic failure:");
98+
assert.include(failure.message, "Synthetic configuration failed.");
9899
for (const value of [
99100
"FixtureOnly",
100101
"AIzaFixture",
@@ -107,6 +108,33 @@ it("redacts prefixed credential fields and escaped quoted values in ACP stderr",
107108
}
108109
});
109110

111+
it("withholds whole ACP stderr lines containing credential markers", () => {
112+
for (const line of [
113+
"AWS_SECRET_ACCESS_KEY=FixtureOnlyValue0123",
114+
"SECRET_KEY=FixtureOnlyValue0123",
115+
"STRIPE_SECRET_KEY=FixtureOnlyValue0123",
116+
JSON.stringify({ clientSecret: "fixture-client-value", refreshToken: "fixture-refresh-value" }),
117+
"secretAccessKey: FixtureOnlyValue",
118+
"Authorization: token FixtureOnlyValue",
119+
"Diagnostic only mentions a password; no value is present.",
120+
"CLIENTSECRET=FixtureOnlyValue",
121+
"GOOGLE_KEY=FixtureOnlyValue",
122+
"Unknown configuration key; no credential is present.",
123+
]) {
124+
const failure = makeProviderFailure({
125+
cause: {
126+
_tag: "AcpProcessExitedError",
127+
code: 23,
128+
stderr: `Synthetic configuration failed.\n${line}\nFinal diagnostic.`,
129+
},
130+
});
131+
assert.equal(
132+
failure.message,
133+
"ACP process exited with code 23\nSynthetic configuration failed.\n[REDACTED credential diagnostic]\nFinal diagnostic.",
134+
);
135+
}
136+
});
137+
110138
it("redacts standalone service tokens in ACP exit diagnostics", () => {
111139
const failure = makeProviderFailure({
112140
cause: {

‎packages/provider-core/src/server/failure.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ function redactProviderFailureText(value: string): string {
184184
.replace(/\bhttps?:\/\/[^\s<>"']+/giu, redactUrl)
185185
.replace(/\b(Bearer|Basic)\s+[^\s,;]+/giu, "$1 [REDACTED]")
186186
.replace(
187-
/(["'](?:[A-Za-z0-9]+[_-])*(?:access[_-]?token|api[_-]?key|private[_-]?key|authorization|credential|password|secret|token)["']\s*:\s*)(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/giu,
188-
'$1"[REDACTED]"',
187+
/(["'](?:access[_-]?token|api[_-]?key|authorization|credential|password|secret|token)["']\s*:\s*["'])[^"']*(["'])/giu,
188+
"$1[REDACTED]$2",
189189
)
190190
.replace(
191-
/(\b(?:[A-Za-z0-9]+[_-])*(?:access[_-]?token|api[_-]?key|private[_-]?key|authorization|credential|password|secret|token)\b\s*[:=]\s*)(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;]+)/giu,
191+
/(\b(?:access[_-]?token|api[_-]?key|authorization|credential|password|secret|token)\b\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu,
192192
"$1[REDACTED]",
193193
)
194194
.replace(/\bsk-[A-Za-z0-9_-]{16,}\b/gu, "[REDACTED]")
@@ -210,7 +210,19 @@ function acpProcessExitDiagnostic(error: Record<string, unknown>) {
210210
: code === undefined
211211
? "ACP process exited"
212212
: `ACP process exited with code ${code}`;
213-
const stderr = typeof error.stderr === "string" ? redactProviderFailureText(error.stderr) : "";
213+
const stderr =
214+
typeof error.stderr === "string"
215+
? redactProviderFailureText(error.stderr)
216+
.split(/\r\n?|\n/u)
217+
.map((line) =>
218+
/token|secret|pass(?:word|wd)|credential|authorization|key/u.test(
219+
line.normalize("NFKC").toLowerCase(),
220+
)
221+
? "[REDACTED credential diagnostic]"
222+
: line,
223+
)
224+
.join("\n")
225+
: "";
214226
const available = MAX_PROVIDER_FAILURE_MESSAGE_LENGTH - summary.length - 1;
215227
let start = Math.max(0, stderr.length - available + 1);
216228
if (start > 0 && /[\uDC00-\uDFFF]/u.test(stderr[start] ?? "")) start += 1;

0 commit comments

Comments
 (0)