Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Normalize protocol-relative remote host input as https (#3971)

Kriday Davec49d424e3aa2
diff --git a/packages/shared/src/remote.test.ts b/packages/shared/src/remote.test.ts
index 24e787570..5b7a99736 100644
--- a/packages/shared/src/remote.test.ts
+++ b/packages/shared/src/remote.test.ts
@@ -59,6 +59,70 @@ describe("remote", () => {
});
});
+ it("treats a protocol-relative host as https", () => {
+ expect(
+ resolveRemotePairingTarget({
+ host: "//remote.example.com",
+ pairingCode: "pairing-token",
+ }),
+ ).toEqual({
+ credential: "pairing-token",
+ httpBaseUrl: "https://remote.example.com/",
+ wsBaseUrl: "wss://remote.example.com/",
+ });
+ });
+
+ it("preserves the port when normalizing a protocol-relative host", () => {
+ expect(
+ resolveRemotePairingTarget({
+ host: "//remote.example.com:3000",
+ pairingCode: "pairing-token",
+ }),
+ ).toEqual({
+ credential: "pairing-token",
+ httpBaseUrl: "https://remote.example.com:3000/",
+ wsBaseUrl: "wss://remote.example.com:3000/",
+ });
+ });
+
+ it("normalizes a protocol-relative host from a hosted pairing link", () => {
+ expect(
+ resolveRemotePairingTarget({
+ pairingUrl: "https://app.t3.codes/pair?host=%2F%2Fremote.example.com#token=pairing-token",
+ }),
+ ).toEqual({
+ credential: "pairing-token",
+ httpBaseUrl: "https://remote.example.com/",
+ wsBaseUrl: "wss://remote.example.com/",
+ });
+ });
+
+ it("collapses extra leading slashes instead of producing an empty host", () => {
+ expect(
+ resolveRemotePairingTarget({
+ host: "///example.com",
+ pairingCode: "pairing-token",
+ }),
+ ).toEqual({
+ credential: "pairing-token",
+ httpBaseUrl: "https://example.com/",
+ wsBaseUrl: "wss://example.com/",
+ });
+ });
+
+ it("does not double-prepend https when the host already carries a scheme", () => {
+ expect(
+ resolveRemotePairingTarget({
+ host: "//https://example.com",
+ pairingCode: "pairing-token",
+ }),
+ ).toEqual({
+ credential: "pairing-token",
+ httpBaseUrl: "https://example.com/",
+ wsBaseUrl: "wss://example.com/",
+ });
+ });
+
it("preserves host ports when normalizing a bare host input", () => {
expect(
resolveRemotePairingTarget({
diff --git a/packages/shared/src/remote.ts b/packages/shared/src/remote.ts
index 7347dbc74..0adfc6fe9 100644
--- a/packages/shared/src/remote.ts
+++ b/packages/shared/src/remote.ts
@@ -81,10 +81,10 @@ const normalizeRemoteBaseUrl = (
throw new RemoteBackendUrlMissingError();
}
- const normalizedInput =
- /^[a-zA-Z][a-zA-Z\d+-]*:\/\//.test(trimmed) || trimmed.startsWith("//")
- ? trimmed
- : `https://${trimmed}`;
+ const withoutLeadingSlashes = trimmed.replace(/^\/+/, "");
+ const normalizedInput = /^[a-zA-Z][a-zA-Z\d+-]*:\/\//.test(withoutLeadingSlashes)
+ ? withoutLeadingSlashes
+ : `https://${withoutLeadingSlashes}`;
let url: URL;
try {
url = new URL(normalizedInput);