@devries-cameron20 / t3code Mirror · read-only / commits / 8919ae7c53
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 21:30 UTC

[codex] Reject unsupported remote pairing protocols (#3498)

Co-authored-by: Codex <codex@openai.com>

Wout Stiens committed Jun 22, 2026 at 19:15 UTC 8919ae7c53973048827481ecc3a96d4d778955f7
2 files changed +68 -2
packages/shared/src/remote.test.ts
+47
@@ -72,6 +72,53 @@ describe("remote", () => {
72 });
73 });
74
75 + it("rejects unsupported direct pairing URL protocols", () => {
76 + let pairingUrlError: unknown;
77 + try {
78 + resolveRemotePairingTarget({
79 + pairingUrl: "ftp://remote.example.com/pair#token=pairing-token",
80 + });
81 + } catch (cause) {
82 + pairingUrlError = cause;
83 + }
84 +
85 + expect(pairingUrlError).toBeInstanceOf(RemotePairingUrlInvalidError);
86 + expect(pairingUrlError).toMatchObject({ protocol: "ftp:" });
87 + expect((pairingUrlError as RemotePairingUrlInvalidError).cause).toBeUndefined();
88 + });
89 +
90 + it("rejects unsupported hosted pairing backend protocols", () => {
91 + let hostError: unknown;
92 + try {
93 + resolveRemotePairingTarget({
94 + pairingUrl:
95 + "https://app.t3.codes/pair?host=ftp%3A%2F%2Fremote.example.com#token=pairing-token",
96 + });
97 + } catch (cause) {
98 + hostError = cause;
99 + }
100 +
101 + expect(hostError).toBeInstanceOf(RemoteBackendUrlInvalidError);
102 + expect(hostError).toMatchObject({ source: "hosted-pairing-host", protocol: "ftp:" });
103 + expect((hostError as RemoteBackendUrlInvalidError).cause).toBeUndefined();
104 + });
105 +
106 + it("rejects unsupported direct host protocols", () => {
107 + let hostError: unknown;
108 + try {
109 + resolveRemotePairingTarget({
110 + host: "ftp://remote.example.com",
111 + pairingCode: "pairing-token",
112 + });
113 + } catch (cause) {
114 + hostError = cause;
115 + }
116 +
117 + expect(hostError).toBeInstanceOf(RemoteBackendUrlInvalidError);
118 + expect(hostError).toMatchObject({ source: "direct-host", protocol: "ftp:" });
119 + expect((hostError as RemoteBackendUrlInvalidError).cause).toBeUndefined();
120 + });
121 +
122 it("uses distinct structural errors for missing pairing inputs", () => {
123 expect(() => resolveRemotePairingTarget({})).toThrowError(RemoteBackendUrlMissingError);
124 expect(() =>
packages/shared/src/remote.ts
+21 -2
@@ -3,6 +3,7 @@ import * as Schema from "effect/Schema";
3 const PAIRING_TOKEN_PARAM = "token";
4 const HOSTED_PAIRING_HOST_PARAM = "host";
5 const HOSTED_PAIRING_LABEL_PARAM = "label";
6 +const SUPPORTED_REMOTE_BACKEND_PROTOCOLS = new Set(["http:", "https:", "ws:", "wss:"]);
7
8 const readHashParams = (url: URL): URLSearchParams =>
9 new URLSearchParams(url.hash.startsWith("#") ? url.hash.slice(1) : url.hash);
@@ -18,7 +19,10 @@ export class RemoteBackendUrlMissingError extends Schema.TaggedErrorClass<Remote
19
20 export class RemotePairingUrlInvalidError extends Schema.TaggedErrorClass<RemotePairingUrlInvalidError>()(
21 "RemotePairingUrlInvalidError",
21 - { cause: Schema.Defect() },
22 + {
23 + cause: Schema.optional(Schema.Defect()),
24 + protocol: Schema.optional(Schema.String),
25 + },
26 ) {
27 override get message(): string {
28 return "Pairing URL is invalid.";
@@ -29,7 +33,8 @@ export class RemoteBackendUrlInvalidError extends Schema.TaggedErrorClass<Remote
33 "RemoteBackendUrlInvalidError",
34 {
35 source: Schema.Literals(["direct-host", "hosted-pairing-host"]),
32 - cause: Schema.Defect(),
36 + cause: Schema.optional(Schema.Defect()),
37 + protocol: Schema.optional(Schema.String),
38 },
39 ) {
40 override get message(): string {
@@ -64,6 +69,9 @@ export const RemotePairingTargetError = Schema.Union([
69 ]);
70 export type RemotePairingTargetError = typeof RemotePairingTargetError.Type;
71
72 +const hasSupportedRemoteBackendProtocol = (url: URL): boolean =>
73 + SUPPORTED_REMOTE_BACKEND_PROTOCOLS.has(url.protocol);
74 +
75 const normalizeRemoteBaseUrl = (
76 rawValue: string,
77 source: RemoteBackendUrlInvalidError["source"],
@@ -83,6 +91,12 @@ const normalizeRemoteBaseUrl = (
91 } catch (cause) {
92 throw new RemoteBackendUrlInvalidError({ source, cause });
93 }
94 + if (!hasSupportedRemoteBackendProtocol(url)) {
95 + throw new RemoteBackendUrlInvalidError({
96 + source,
97 + protocol: url.protocol,
98 + });
99 + }
100 url.pathname = "/";
101 url.search = "";
102 url.hash = "";
@@ -184,6 +198,11 @@ export const resolveRemotePairingTarget = (input: {
198 } catch (cause) {
199 throw new RemotePairingUrlInvalidError({ cause });
200 }
201 + if (!hasSupportedRemoteBackendProtocol(url)) {
202 + throw new RemotePairingUrlInvalidError({
203 + protocol: url.protocol,
204 + });
205 + }
206 const hostedPairingRequest = readHostedPairingRequest(url);
207 if (hostedPairingRequest) {
208 const hostedBackendUrl = normalizeRemoteBaseUrl(