Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-ipv6-session-broker-origins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hunkdiff": patch
---

Fix session commands when the local daemon uses the IPv6 loopback address.
14 changes: 14 additions & 0 deletions src/session-broker/brokerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ describe("Hunk session daemon config", () => {
).toMatchObject({ host: "localhost", port: 49000 });
});

test("formats IPv6 literal origins with URL authority brackets", () => {
expect(
resolveSessionBrokerConfig({
[SESSION_BROKER_HOST_ENV]: "::1",
[SESSION_BROKER_PORT_ENV]: "49000",
}),
).toMatchObject({
host: "::1",
port: 49000,
httpOrigin: "http://[::1]:49000",
wsOrigin: "ws://[::1]:49000",
});
});

test("accepts loopback hosts without an unsafe override", () => {
expect(isLoopbackHost("127.0.0.1")).toBe(true);
expect(isLoopbackHost("127.1.2.3")).toBe(true);
Expand Down
7 changes: 5 additions & 2 deletions src/session-broker/brokerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ export function resolveSessionBrokerConfig(
);
}

// URL authorities require brackets around literal IPv6 addresses, unlike socket APIs.
const urlHost = isIP(host) === 6 ? `[${host}]` : host;

return {
host,
port,
httpOrigin: `http://${host}:${port}`,
wsOrigin: `ws://${host}:${port}`,
httpOrigin: `http://${urlHost}:${port}`,
wsOrigin: `ws://${urlHost}:${port}`,
};
}
Loading