Skip to content

Commit 1dd8c67

Browse files
only21milclaudemaria-rcks
authored
fix(desktop): keep development protocol requests on the configured server (pingdotgg#22010)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 2049052 commit 1dd8c67

2 files changed

Lines changed: 37 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
@@ -130,6 +130,39 @@ describe("ElectronProtocol", () => {
130130
}).pipe(Effect.provide(layerProtocol)),
131131
);
132132

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

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ const proxyRequest = Effect.fn("desktop.protocol.proxyRequest")(function* (
167167
return new Response(null, { status: 404 });
168168
}
169169

170-
const targetUrl = new URL(`${requestUrl.pathname}${requestUrl.search}`, targetOrigin);
170+
// Assign the path so leading slashes cannot replace the configured host.
171+
const targetUrl = new URL(targetOrigin);
172+
targetUrl.pathname = requestUrl.pathname;
173+
targetUrl.search = requestUrl.search;
171174
const headers = new Headers(request.headers);
172175
const headersToRemove: string[] = [];
173176
for (const name of headers.keys()) {

0 commit comments

Comments
 (0)