Skip to content

Commit dcad1fe

Browse files
only21milclaude
andcommitted
fix(desktop): keep development protocol requests on the configured server
The development protocol handler resolved the request path as a relative URL against the dev server. A path starting with `//` (or `/\`) is a network-path reference, so it replaced the dev server's host. Copy the path and query onto the configured URL instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 54983e3 commit dcad1fe

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎apps/desktop/src/electron/ElectronProtocol.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,39 @@ describe("ElectronProtocol", () => {
133133
}).pipe(Effect.provide(layerProtocol)),
134134
);
135135

136+
it.effect("keeps proxied paths on the configured server", () =>
137+
Effect.gen(function* () {
138+
let handler: ((request: Request) => Promise<Response>) | undefined;
139+
handleMock.mockImplementation((_scheme, nextHandler) => {
140+
handler = nextHandler;
141+
});
142+
netFetchMock.mockImplementation(async () => new Response("ok"));
143+
144+
yield* Effect.scoped(
145+
Effect.gen(function* () {
146+
const protocol = yield* ElectronProtocol.ElectronProtocol;
147+
yield* protocol.registerDesktopProtocol({
148+
scheme: "t3code-dev",
149+
targetOrigin: new URL("http://127.0.0.1:5733/"),
150+
clerkFrontendApiHostname: undefined,
151+
});
152+
yield* Effect.promise(() =>
153+
handler!(new Request("t3code-dev://app//example.com/src/main.tsx?t=1")),
154+
);
155+
yield* Effect.promise(() => handler!(new Request("t3code-dev://app/\\example.com/")));
156+
}),
157+
);
158+
159+
assert.deepEqual(
160+
netFetchMock.mock.calls.map((call) => call[0]),
161+
[
162+
"http://127.0.0.1:5733//example.com/src/main.tsx?t=1",
163+
"http://127.0.0.1:5733//example.com/",
164+
],
165+
);
166+
}).pipe(Effect.provide(layerProtocol)),
167+
);
168+
136169
it.effect("rejects custom protocol requests for another host", () =>
137170
Effect.gen(function* () {
138171
let handler: ((request: Request) => Promise<Response>) | undefined;

‎apps/desktop/src/electron/ElectronProtocol.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ const proxyRequest = Effect.fn("desktop.protocol.proxyRequest")(function* (
173173
return new Response(null, { status: 404 });
174174
}
175175

176-
const targetUrl = new URL(`${requestUrl.pathname}${requestUrl.search}`, targetOrigin);
176+
// Copy the path onto the target instead of resolving it, so a path such as
177+
// `//example.com/` cannot replace the configured host.
178+
const targetUrl = new URL(targetOrigin);
179+
targetUrl.pathname = requestUrl.pathname;
180+
targetUrl.search = requestUrl.search;
177181
const headers = new Headers(request.headers);
178182
const headersToRemove: string[] = [];
179183
for (const name of headers.keys()) {

0 commit comments

Comments
 (0)