Skip to content

Commit 6e92e35

Browse files
juliusmarmingecodex
andcommitted
Redact relay revoke warning context
Co-authored-by: codex <[email protected]>
1 parent d25d615 commit 6e92e35

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎apps/web/src/cloud/linkEnvironment.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RelayWebClientId } from "@t3tools/contracts/relay";
88
import { describe, expect, it } from "@effect/vitest";
99
import * as Effect from "effect/Effect";
1010
import * as Layer from "effect/Layer";
11+
import * as Logger from "effect/Logger";
1112
import * as Option from "effect/Option";
1213
import * as Stream from "effect/Stream";
1314
import * as SubscriptionRef from "effect/SubscriptionRef";
@@ -50,12 +51,21 @@ const relayClientInstallDialog = vi.hoisted(() => ({
5051
finish: vi.fn(),
5152
}));
5253

54+
const cloudPublicConfig = vi.hoisted(() => ({
55+
relayUrl: "https://relay.example.test",
56+
}));
57+
5358
vi.mock("./relayClientInstallDialog", () => ({
5459
requestRelayClientInstallConfirmation: relayClientInstallDialog.requestConfirmation,
5560
reportRelayClientInstallProgress: relayClientInstallDialog.reportProgress,
5661
finishRelayClientInstall: relayClientInstallDialog.finish,
5762
}));
5863

64+
vi.mock("./publicConfig", async (importOriginal) => ({
65+
...(await importOriginal<typeof import("./publicConfig")>()),
66+
resolveCloudPublicConfig: () => ({ relayUrl: cloudPublicConfig.relayUrl }),
67+
}));
68+
5969
const createProof = vi.fn(() => Effect.succeed("dpop-proof"));
6070
const dpopSignerLayer = Layer.succeed(
6171
ManagedRelay.ManagedRelayDpopSigner,
@@ -143,6 +153,7 @@ function bodyText(body: BodyInit | null | undefined): string {
143153

144154
beforeEach(() => {
145155
vi.clearAllMocks();
156+
cloudPublicConfig.relayUrl = "https://relay.example.test";
146157
vi.stubEnv("VITE_T3CODE_RELAY_URL", "https://relay.example.test");
147158
relayClientInstallDialog.requestConfirmation.mockResolvedValue(true);
148159
});
@@ -481,4 +492,64 @@ describe("web cloud link environment client", () => {
481492
);
482493
}),
483494
);
495+
496+
it.effect("keeps configured relay URL secrets out of revoke warnings", () => {
497+
const relayUrl =
498+
"https://relay-user:[email protected]/private/workspace?access_token=relay-secret#relay-fragment";
499+
cloudPublicConfig.relayUrl = relayUrl;
500+
const capturedLogs: Array<ReadonlyArray<unknown>> = [];
501+
const logger = Logger.make(({ message }) => {
502+
capturedLogs.push(Array.isArray(message) ? message : [message]);
503+
});
504+
const fetchMock = vi
505+
.fn()
506+
.mockResolvedValueOnce(
507+
Response.json({ ok: true, endpointRuntimeStatus: { status: "disabled" } }),
508+
)
509+
.mockResolvedValueOnce(Response.json({ malformed: true }, { status: 500 }));
510+
vi.stubGlobal("fetch", fetchMock);
511+
512+
return unlinkPrimaryEnvironmentFromCloud({
513+
target: TARGET,
514+
clerkToken: "clerk-token",
515+
}).pipe(
516+
Effect.provide(
517+
Layer.merge(
518+
services(),
519+
Logger.layer([logger], {
520+
mergeWithExisting: false,
521+
}),
522+
),
523+
),
524+
Effect.tap(() =>
525+
Effect.sync(() => {
526+
expect(capturedLogs).toHaveLength(1);
527+
const logFields = capturedLogs[0]?.find(
528+
(value): value is Record<string, unknown> =>
529+
typeof value === "object" && value !== null,
530+
);
531+
expect(logFields).toMatchObject({
532+
relayUrlInputLength: relayUrl.length,
533+
relayUrlProtocol: "https:",
534+
relayUrlHostname: "relay.example.test",
535+
});
536+
expect(logFields).not.toHaveProperty("relayUrl");
537+
const logText = [
538+
...(capturedLogs[0]?.filter((value): value is string => typeof value === "string") ??
539+
[]),
540+
String(logFields?.cause),
541+
].join(" ");
542+
for (const secret of [
543+
"relay-user",
544+
"relay-password",
545+
"/private/workspace",
546+
"access_token=relay-secret",
547+
"relay-fragment",
548+
]) {
549+
expect(logText).not.toContain(secret);
550+
}
551+
}),
552+
),
553+
);
554+
});
484555
});

‎apps/web/src/cloud/linkEnvironment.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,15 @@ export function unlinkPrimaryEnvironmentFromCloud(input: {
596596
});
597597
return Effect.logWarning(error.message, {
598598
environmentId: input.target.environmentId,
599-
relayUrl: configuredRelayUrl,
599+
...(error.relayUrlInputLength === undefined
600+
? {}
601+
: { relayUrlInputLength: error.relayUrlInputLength }),
602+
...(error.relayUrlProtocol === undefined
603+
? {}
604+
: { relayUrlProtocol: error.relayUrlProtocol }),
605+
...(error.relayUrlHostname === undefined
606+
? {}
607+
: { relayUrlHostname: error.relayUrlHostname }),
600608
cause: error,
601609
});
602610
}),

0 commit comments

Comments
 (0)