From bf555bd9fa8f0eb0c414b1cb534acede94d19cc2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 20 Jun 2026 10:06:01 -0700 Subject: [PATCH] fix(server): redact managed endpoint output Co-authored-by: codex --- .../src/cloud/ManagedEndpointRuntime.test.ts | 64 ++++++++++++++++++- .../src/cloud/ManagedEndpointRuntime.ts | 3 +- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/apps/server/src/cloud/ManagedEndpointRuntime.test.ts b/apps/server/src/cloud/ManagedEndpointRuntime.test.ts index 1bdc66e5b7..d54cab739d 100644 --- a/apps/server/src/cloud/ManagedEndpointRuntime.test.ts +++ b/apps/server/src/cloud/ManagedEndpointRuntime.test.ts @@ -65,6 +65,7 @@ function makeHandle(input: { readonly isRunning?: () => boolean; readonly isRunningEffect?: ChildProcessSpawner.ChildProcessHandle["isRunning"]; readonly exitCode?: Effect.Effect; + readonly output?: string; }) { return ChildProcessSpawner.makeHandle({ pid: ChildProcessSpawner.ProcessId(input.pid), @@ -78,7 +79,10 @@ function makeHandle(input: { stdin: Sink.drain, stdout: Stream.empty, stderr: Stream.empty, - all: Stream.empty, + all: + input.output === undefined + ? Stream.empty + : Stream.make(new TextEncoder().encode(input.output)), getInputFd: () => Sink.drain, getOutputFd: () => Stream.empty, }); @@ -262,6 +266,64 @@ describe("CloudManagedEndpointRuntime", () => { }).pipe(Effect.provide(Logger.layer([logger], { mergeWithExisting: false }))); }); + it.effect("does not copy relay client output into log annotations", () => { + const connectorToken = "connector-token-sentinel"; + const signedUrl = "https://user:password@example.com/private?token=secret#fragment"; + const output = `ERR failed request ${signedUrl} ${connectorToken}`; + const logMessages: unknown[] = []; + let resolveObserved!: () => void; + const observed = new Promise((resolve) => { + resolveObserved = resolve; + }); + const logger = Logger.make(({ message }) => { + logMessages.push(message); + if (Array.isArray(message) && message[0] === "Relay client reported a transport warning") { + resolveObserved(); + } + }); + const spawner = ChildProcessSpawner.make(() => + Effect.gen(function* () { + const handle = makeHandle({ + pid: 350, + output, + onKill: () => undefined, + }); + yield* Effect.addFinalizer(() => handle.kill().pipe(Effect.ignore)); + return handle; + }), + ); + + return Effect.gen(function* () { + const runtime = yield* buildCloudManagedEndpointRuntime(spawner); + yield* runtime.applyConfig({ + providerKind: "cloudflare_tunnel", + connectorToken, + tunnelId: "tunnel-1", + }); + yield* Effect.promise(() => observed); + + const warning = logMessages.find( + (message) => + Array.isArray(message) && message[0] === "Relay client reported a transport warning", + ); + expect(warning).toBeDefined(); + if (!Array.isArray(warning)) return; + expect(warning[1]).toMatchObject({ + pid: 350, + tunnelId: "tunnel-1", + outputLength: output.length, + }); + expect(warning[1]).not.toHaveProperty("output"); + const diagnosticText = Object.values(warning[1] as Record) + .map(String) + .join("\n"); + expect(diagnosticText).not.toContain(connectorToken); + expect(diagnosticText).not.toContain(signedUrl); + expect(diagnosticText).not.toContain("user:password"); + expect(diagnosticText).not.toContain("token=secret"); + }).pipe(Effect.provide(Logger.layer([logger], { mergeWithExisting: false }))); + }); + it.effect("supervises the active connector and restarts it after process exit", () => Effect.gen(function* () { const spawned: Array = []; diff --git a/apps/server/src/cloud/ManagedEndpointRuntime.ts b/apps/server/src/cloud/ManagedEndpointRuntime.ts index 1e5566b8c1..8114b95be1 100644 --- a/apps/server/src/cloud/ManagedEndpointRuntime.ts +++ b/apps/server/src/cloud/ManagedEndpointRuntime.ts @@ -183,12 +183,11 @@ export const make = Effect.gen(function* () { Stream.map((line) => line.trim()), Stream.filter((line) => line.length > 0), Stream.runForEach((line) => { - const output = line.replaceAll(connector.config.connectorToken, ""); const attributes = { pid: Number(connector.child.pid), tunnelId: connector.config.tunnelId, tunnelName: connector.config.tunnelName, - output, + outputLength: line.length, }; switch (classifyRelayClientOutput(line)) { case "connected":