@devries-cameron20 / t3code Mirror · read-only / commits / 0517d15c41
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 21, 16:00 UTC

fix(web): provider sign-in links only open web addresses (#36392)

Julius Marminge committed Nov 13, 2026 at 13:07 UTC 0517d15c41e95c9d84d8014ae14394ce97bc83f6
6 files changed +54 -12
apps/web/src/browser/browserLinkTarget.ts
+3 -9
@@ -7,6 +7,9 @@ import {
7 import { ensureClientSettingsHydrated, getClientSettings } from "~/hooks/useSettings";
8 import { readEnvironmentScope } from "~/state/session";
9 import { isPreviewAvailableFor } from "./previewRuntime";
10 +import { isWebUrl } from "./webUrl";
11 +
12 +export { isWebUrl };
13
14 export interface ResolveLinkTargetInput {
15 readonly url: string;
@@ -27,15 +30,6 @@ export function resolveLinkTarget(input: ResolveLinkTargetInput): BrowserLinkTar
30 return "app";
31 }
32
30 -export function isWebUrl(url: string): boolean {
31 - try {
32 - const { protocol } = new URL(url);
33 - return protocol === "http:" || protocol === "https:";
34 - } catch {
35 - return false;
36 - }
37 -}
38 -
33 /** Before hydration, the default "system" would ignore a saved "app" link target. */
34 export async function resolveBrowserLinkTargetPreference(): Promise<BrowserLinkTarget> {
35 await ensureClientSettingsHydrated();
apps/web/src/browser/webUrl.ts new
+8
@@ -0,0 +1,8 @@
1 +export function isWebUrl(url: string): boolean {
2 + try {
3 + const { protocol } = new URL(url);
4 + return protocol === "http:" || protocol === "https:";
5 + } catch {
6 + return false;
7 + }
8 +}
apps/web/src/components/settings/ProviderAuthenticationSection.tsx
+5
@@ -14,6 +14,7 @@ import { lazy, Suspense, useRef, useState } from "react";
14 import { CopyIcon } from "lucide-react";
15
16 import { writeTextToClipboard } from "../../hooks/useCopyToClipboard";
17 +import { isWebUrl } from "../../browser/webUrl";
18 import { ensureLocalApi } from "../../localApi";
19 import { useEnvironmentQuery } from "../../state/query";
20 import { serverEnvironment } from "../../state/server";
@@ -141,6 +142,10 @@ export function ProviderAuthenticationSection({
142
143 async function openBrowser() {
144 if (!url || readOnly) return;
145 + if (!isWebUrl(url)) {
146 + setError("This sign-in link is not a web address, so it was not opened.");
147 + return;
148 + }
149 const requiresConsent = interaction?.type === "browser" && interaction.requiresConsent;
150 // Reserve tabs before awaiting consent; browsers block later opens.
151 const pending = requiresConsent && !window.desktopBridge ? window.open("", "_blank") : null;
apps/web/src/localApi.ts
+2
@@ -1,5 +1,6 @@
1 import type { ConfirmDialogOptions, ContextMenuItem, LocalApi } from "@t3tools/contracts";
2
3 +import { isWebUrl } from "./browser/webUrl";
4 import { requestConfirmDialog } from "./confirmDialog";
5 import { dismissContextMenu, showContextMenuFallback } from "./contextMenuFallback";
6 import { readBrowserClientSettings, writeBrowserClientSettings } from "./clientPersistenceStorage";
@@ -27,6 +28,7 @@ export function createLocalApi(): LocalApi {
28 return;
29 }
30
31 + if (!isWebUrl(url)) throw new Error("Unable to open link.");
32 window.open(url, "_blank", "noopener,noreferrer");
33 },
34 openSystemSettings: async (pane) => {
packages/contracts/src/providerSetup.test.ts
+28
@@ -30,4 +30,32 @@ describe("provider auth state", () => {
30 methods: [method],
31 });
32 });
33 +
34 + it("refuses sign-in URLs that are not web pages", () => {
35 + const state = {
36 + instanceId: "cursor",
37 + phase: "waiting",
38 + flowId: "flow",
39 + authorizationUrl: null,
40 + expiresAt: null,
41 + message: null,
42 + };
43 + const script = "javascript:alert(document.domain)";
44 + expect(
45 + decodeState({
46 + ...state,
47 + interaction: { type: "browser", id: "b", url: script, requiresConsent: true },
48 + }),
49 + ).toEqual(state);
50 + expect(
51 + decodeState({
52 + ...state,
53 + interaction: { type: "deviceCode", id: "d", url: script, userCode: "ABCD" },
54 + }),
55 + ).toEqual(state);
56 + expect(() => decodeState({ ...state, authorizationUrl: script })).toThrow();
57 + expect(
58 + decodeState({ ...state, authorizationUrl: "https://cursor.com/login" }).authorizationUrl,
59 + ).toBe("https://cursor.com/login");
60 + });
61 });
packages/contracts/src/providerSetup.ts
+8 -3
@@ -15,6 +15,11 @@ export const ProviderSetupInput = Schema.Struct({
15 export type ProviderSetupInput = typeof ProviderSetupInput.Type;
16
17 const SetupOperationId = TrimmedNonEmptyString.check(Schema.isMaxLength(128));
18 +// Environments supply these and clients open them, so a `javascript:` URL would run as the client.
19 +const SignInUrl = TrimmedNonEmptyString.check(
20 + Schema.isMaxLength(16_384),
21 + Schema.isPattern(/^https?:\/\//i),
22 +);
23
24 export const ProviderAuthMethod = Schema.Struct({
25 id: SetupOperationId,
@@ -30,14 +35,14 @@ export const ProviderAuthInteraction = Schema.Union([
35 Schema.Struct({
36 type: Schema.Literal("browser"),
37 id: SetupOperationId,
33 - url: TrimmedNonEmptyString.check(Schema.isMaxLength(16_384)),
38 + url: SignInUrl,
39 requiresConsent: Schema.Boolean,
40 acceptsCallback: Schema.optionalKey(Schema.Boolean),
41 }),
42 Schema.Struct({
43 type: Schema.Literal("deviceCode"),
44 id: SetupOperationId,
40 - url: TrimmedNonEmptyString.check(Schema.isMaxLength(16_384)),
45 + url: SignInUrl,
46 userCode: TrimmedNonEmptyString.check(Schema.isMaxLength(256)),
47 }),
48 Schema.Struct({
@@ -117,7 +122,7 @@ export const ProviderAuthState = Schema.Struct({
122 "cancelled",
123 ]),
124 flowId: Schema.NullOr(SetupOperationId),
120 - authorizationUrl: Schema.NullOr(Schema.String),
125 + authorizationUrl: Schema.NullOr(SignInUrl),
126 expiresAt: Schema.NullOr(IsoDateTime),
127 message: Schema.NullOr(Schema.String),
128 // Drop unknown auth methods rather than rejecting the entire state.