Skip to content

Commit c7db911

Browse files
juliusmarmingecodex
andcommitted
Redact browser target URL diagnostics
Co-authored-by: codex <[email protected]>
1 parent 181f03c commit c7db911

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎apps/web/src/browser/browserTargetResolver.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ describe("browser target resolver", () => {
6565
});
6666

6767
it("preserves invalid environment URL causes with connection context", async () => {
68-
readPreparedConnection.mockReturnValue({ httpBaseUrl: "not a url" });
68+
const sensitiveUrl =
69+
"https://user:password@[invalid-host]/private/workspace?access_token=secret#fragment";
70+
readPreparedConnection.mockReturnValue({ httpBaseUrl: sensitiveUrl });
6971
const { BrowserTargetEnvironmentUrlInvalidError, resolveBrowserNavigationTarget } =
7072
await import("./browserTargetResolver");
7173

@@ -79,11 +81,17 @@ describe("browser target resolver", () => {
7981
expect(error).toMatchObject({
8082
_tag: "BrowserTargetEnvironmentUrlInvalidError",
8183
environmentId: "environment-1",
82-
httpBaseUrl: "not a url",
84+
httpBaseUrlInputLength: sensitiveUrl.length,
8385
cause: expect.any(TypeError),
84-
message: "Environment environment-1 has an invalid HTTP base URL: not a url.",
86+
message: `Environment environment-1 has an invalid HTTP base URL input of length ${sensitiveUrl.length}.`,
8587
});
8688
expect(error).toBeInstanceOf(BrowserTargetEnvironmentUrlInvalidError);
89+
expect(error).not.toHaveProperty("httpBaseUrl");
90+
expect(error).not.toHaveProperty("httpBaseUrlProtocol");
91+
expect(error).not.toHaveProperty("httpBaseUrlHostname");
92+
expect(String((error as Error).message)).not.toMatch(
93+
/user|password|private|workspace|access_token|secret|fragment/,
94+
);
8795
}
8896
});
8997

‎apps/web/src/browser/browserTargetResolver.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type PreviewUrlResolution,
55
} from "@t3tools/contracts";
66
import { isLoopbackHost, normalizePreviewUrl } from "@t3tools/shared/preview";
7+
import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics";
78
import * as Schema from "effect/Schema";
89

910
import { readPreparedConnection } from "~/state/session";
@@ -23,12 +24,14 @@ export class BrowserTargetEnvironmentUrlInvalidError extends Schema.TaggedErrorC
2324
"BrowserTargetEnvironmentUrlInvalidError",
2425
{
2526
environmentId: EnvironmentId,
26-
httpBaseUrl: Schema.String,
27+
httpBaseUrlInputLength: Schema.Number,
28+
httpBaseUrlProtocol: Schema.optionalKey(Schema.String),
29+
httpBaseUrlHostname: Schema.optionalKey(Schema.String),
2730
cause: Schema.Defect(),
2831
},
2932
) {
3033
override get message(): string {
31-
return `Environment ${this.environmentId} has an invalid HTTP base URL: ${this.httpBaseUrl}.`;
34+
return `Environment ${this.environmentId} has an invalid HTTP base URL input of length ${this.httpBaseUrlInputLength}.`;
3235
}
3336
}
3437

@@ -81,9 +84,12 @@ export function resolveBrowserNavigationTarget(
8184
try {
8285
environmentUrl = new URL(connection.httpBaseUrl);
8386
} catch (cause) {
87+
const diagnostics = getUrlDiagnostics(connection.httpBaseUrl);
8488
throw new BrowserTargetEnvironmentUrlInvalidError({
8589
environmentId,
86-
httpBaseUrl: connection.httpBaseUrl,
90+
httpBaseUrlInputLength: diagnostics.inputLength,
91+
...(diagnostics.protocol === undefined ? {} : { httpBaseUrlProtocol: diagnostics.protocol }),
92+
...(diagnostics.hostname === undefined ? {} : { httpBaseUrlHostname: diagnostics.hostname }),
8793
cause,
8894
});
8995
}

0 commit comments

Comments
 (0)