Skip to content

Commit 0c140a7

Browse files
committed
fix(server): sanitize preview failure diagnostics
1 parent 2dc261f commit 0c140a7

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,26 +2699,31 @@ it.live("reports why a page failed to load while the tab shows the error page",
26992699
).pipe(Effect.provide(layer)),
27002700
);
27012701

2702-
it.live("preview_open rejects a desktop navigation that failed before automation attached", () =>
2702+
it.effect("preview_open rejects a desktop navigation that failed before automation attached", () =>
27032703
Effect.scoped(
27042704
Effect.gen(function* () {
27052705
const { broker, tabId } = yield* ready;
27062706
const manager = yield* Manager.PreviewManager;
27072707
const channel = yield* DesktopChannel.DesktopBrowserChannel;
27082708
desktopRendersNext = true;
27092709
desktopPageUrl = "chrome-error://chromewebdata/";
2710-
using _failure = vi.spyOn(channel, "loadFailure").mockReturnValue(certificateError);
2710+
const failure = {
2711+
...certificateError,
2712+
url: "https://user:[email protected]/?token=private#fragment",
2713+
};
2714+
using _failure = vi.spyOn(channel, "loadFailure").mockReturnValue(failure);
27112715
const error = yield* broker
27122716
.invoke<PreviewAutomationStatus>({
27132717
scope,
27142718
operation: "open",
2715-
input: { url: certificateError.url, reuseExistingTab: false, open: false },
2719+
input: { url: failure.url, reuseExistingTab: false, open: false },
27162720
})
27172721
.pipe(Effect.flip);
27182722
expect(error).toMatchObject({
27192723
_tag: "PreviewAutomationExecutionError",
27202724
reason: `Navigation to ${certificateError.url} failed: ${certificateError.description}`,
27212725
});
2726+
expect(JSON.stringify(error)).not.toMatch(/secret|private|fragment/);
27222727
const { sessions } = yield* manager.list({ threadId: scope.thread.threadId });
27232728
expect(sessions.map((session) => session.tabId)).toEqual([tabId]);
27242729
}),

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,10 +1627,20 @@ const make = Effect.gen(function* () {
16271627
const assertNavigationSucceeded = (tab: ServerTab) => {
16281628
const failure = loadErrorOf(tab);
16291629
if (failure) {
1630+
const diagnosticUrl = URL.parse(failure.url);
1631+
if (diagnosticUrl) {
1632+
diagnosticUrl.username = "";
1633+
diagnosticUrl.password = "";
1634+
diagnosticUrl.search = "";
1635+
diagnosticUrl.hash = "";
1636+
}
1637+
const url = diagnosticUrl
1638+
? ServerBrowserPage.withoutDataPayload(diagnosticUrl.href)
1639+
: "the requested page";
16301640
throw new ServerBrowserPage.ServerBrowserOperationError({
16311641
tag: "PreviewAutomationExecutionError",
1632-
message: `Navigation to ${failure.url} failed: ${failure.description}`,
1633-
detail: failure,
1642+
message: `Navigation to ${url} failed: ${failure.description}`,
1643+
detail: { ...failure, url },
16341644
});
16351645
}
16361646
};

0 commit comments

Comments
 (0)