Skip to content

Commit f71255e

Browse files
committed
fix(agents): redact service request diagnostics
1 parent 64a76d1 commit f71255e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/agents/provider-local-service.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,18 +762,24 @@ describe("provider local service", () => {
762762
const healthUrl = `http://127.0.0.1:${port}/v1/models`;
763763
const diagnosticSecret = "local-service-diagnostic-secret";
764764
const inheritedDiagnosticSecret = "inherited-local-service-diagnostic-secret";
765+
const headerDiagnosticSecret = "header-local-service-diagnostic-secret";
766+
const argumentDiagnosticSecret = "argument-local-service-diagnostic-secret";
765767
let startupError: Error | undefined;
766768
vi.stubEnv("INHERITED_DIAGNOSTIC_TOKEN", inheritedDiagnosticSecret);
767769

768770
try {
769771
await ensureProviderLocalService({
770772
providerId: "local-diagnostics",
771773
baseUrl: `http://127.0.0.1:${port}/v1`,
774+
headers: {
775+
Authorization: `Bearer ${headerDiagnosticSecret}`,
776+
},
772777
service: {
773778
command: process.execPath,
774779
args: [
775780
"-e",
776-
`const noise="x".repeat(9000);process.stderr.write(noise+" "+process.env.DIAGNOSTIC_SECRET+" "+process.env.INHERITED_DIAGNOSTIC_TOKEN);process.exit(17);`,
781+
`const http=require("node:http");const noise="x".repeat(9000);const server=http.createServer((req,res)=>{process.stderr.write(noise+" "+process.env.DIAGNOSTIC_SECRET+" "+process.env.INHERITED_DIAGNOSTIC_TOKEN+" "+process.argv[1]+" "+req.headers.authorization);res.writeHead(503,{"connection":"close"});res.end("not ready");server.close();setTimeout(()=>process.exit(17),20);});server.listen(${port},"127.0.0.1");`,
782+
argumentDiagnosticSecret,
777783
],
778784
env: { DIAGNOSTIC_SECRET: diagnosticSecret },
779785
healthUrl,
@@ -793,6 +799,8 @@ describe("provider local service", () => {
793799
expect(startupError?.message).toContain("[redacted]");
794800
expect(startupError?.message).not.toContain(diagnosticSecret);
795801
expect(startupError?.message).not.toContain(inheritedDiagnosticSecret);
802+
expect(startupError?.message).not.toContain(headerDiagnosticSecret);
803+
expect(startupError?.message).not.toContain(argumentDiagnosticSecret);
796804
expect(Buffer.byteLength(startupError?.message ?? "")).toBeLessThanOrEqual(8 * 1024 + 256);
797805
expect(getManagedProviderLocalServiceDiagnosticsForTest()).toEqual([]);
798806
});

src/agents/provider-local-service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ async function startAndWaitForLocalService(params: {
434434
chunk,
435435
service.env,
436436
process.env,
437+
service.args,
438+
healthHeaders,
437439
);
438440
};
439441
const captureStderr = (chunk: Buffer | string) => {
@@ -442,6 +444,8 @@ async function startAndWaitForLocalService(params: {
442444
chunk,
443445
service.env,
444446
process.env,
447+
service.args,
448+
healthHeaders,
445449
);
446450
};
447451
child.stdout?.on("data", captureStdout);
@@ -504,6 +508,8 @@ function appendLocalServiceOutputTail(
504508
chunk: Buffer | string,
505509
serviceEnv: Record<string, string> | undefined,
506510
inheritedEnv: NodeJS.ProcessEnv,
511+
serviceArgs: string[] | undefined,
512+
healthHeaders: HeadersInit | undefined,
507513
): string {
508514
let redacted = redactSensitiveText(`${current}${chunk.toString()}`, { mode: "tools" });
509515
for (const value of Object.values(serviceEnv ?? {})) {
@@ -516,6 +522,16 @@ function appendLocalServiceOutputTail(
516522
redacted = redacted.replaceAll(value, "[redacted]");
517523
}
518524
}
525+
for (const value of serviceArgs ?? []) {
526+
if (value) {
527+
redacted = redacted.replaceAll(value, "[redacted]");
528+
}
529+
}
530+
for (const [, value] of new Headers(healthHeaders)) {
531+
if (value) {
532+
redacted = redacted.replaceAll(value, "[redacted]");
533+
}
534+
}
519535
const bytes = Buffer.from(redacted);
520536
if (bytes.byteLength <= LOCAL_SERVICE_OUTPUT_TAIL_MAX_BYTES) {
521537
return redacted;

0 commit comments

Comments
 (0)