@devries-cameron20 / t3code-1 / commits / ba640037e8
Fork 0

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

fix(desktop): require user consent for preview actions (#37866)

Julius Marminge committed Nov 18, 2026 at 17:24 UTC ba640037e82dde3009d1b99573a20414c0dec89b
16 files changed +83 -36
apps/desktop/src/i18n/translations/de.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code konnte diese Genehmigung nicht speichern, daher bleibt die Seite blockiert. Prüfe, ob die Festplatte voll ist und ob ihr Datenordner beschreibbar ist, und versuche es dann erneut.",
50 "a0315d43e8e5be7e": "Erlauben",
51 "2ec823ca24387055": "Blockieren",
52 + "709219ff9ff49a4f": "{origin} möchte deinen Standort erfahren",
53 "8fc0b116123fb50b": "{origin} möchte in die Zwischenablage kopierte Texte und Bilder sehen",
54 "c0f756221736393f": "Vorschau · {title}",
55 "6994444f4fec4070": "Browservorschau",
apps/desktop/src/i18n/translations/en.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code could not save this approval, so the page stays blocked. Check that the disk is not full and its data folder is writable, then try again.",
50 "a0315d43e8e5be7e": "Allow",
51 "2ec823ca24387055": "Block",
52 + "709219ff9ff49a4f": "{origin} wants to know your location",
53 "8fc0b116123fb50b": "{origin} wants to see text and images copied to the clipboard",
54 "c0f756221736393f": "Preview · {title}",
55 "6994444f4fec4070": "Browser preview",
apps/desktop/src/i18n/translations/es.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code no pudo guardar esta aprobación, así que la página sigue bloqueada. Comprueba que el disco no está lleno y que se puede escribir en su carpeta de datos y vuelve a intentarlo.",
50 "a0315d43e8e5be7e": "Permitir",
51 "2ec823ca24387055": "Bloquear",
52 + "709219ff9ff49a4f": "{origin} quiere conocer tu ubicación",
53 "8fc0b116123fb50b": "{origin} quiere ver el texto y las imágenes copiados al portapapeles",
54 "c0f756221736393f": "Vista previa · {title}",
55 "6994444f4fec4070": "Vista previa del navegador",
apps/desktop/src/i18n/translations/fr.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code n’a pas pu enregistrer cette approbation, la page reste donc bloquée. Vérifiez que le disque n’est pas plein et que son dossier de données est accessible en écriture, puis réessayez.",
50 "a0315d43e8e5be7e": "Autoriser",
51 "2ec823ca24387055": "Bloquer",
52 + "709219ff9ff49a4f": "{origin} souhaite connaître votre position",
53 "8fc0b116123fb50b": "{origin} veut voir le texte et les images copiés dans le presse-papiers",
54 "c0f756221736393f": "Aperçu · {title}",
55 "6994444f4fec4070": "Aperçu du navigateur",
apps/desktop/src/i18n/translations/ja.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code はこの承認を保存できなかったため、ページはブロックされたままです。ディスクがいっぱいでないこと、データフォルダーに書き込めることを確認してから、もう一度お試しください。",
50 "a0315d43e8e5be7e": "許可",
51 "2ec823ca24387055": "ブロック",
52 + "709219ff9ff49a4f": "{origin} が位置情報へのアクセスを求めています",
53 "8fc0b116123fb50b": "{origin} がクリップボードにコピーされたテキストと画像の表示を求めています",
54 "c0f756221736393f": "プレビュー · {title}",
55 "6994444f4fec4070": "ブラウザープレビュー",
apps/desktop/src/i18n/translations/ko.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code가 이 승인을 저장하지 못해 페이지가 계속 차단됩니다. 디스크가 가득 차지 않았는지, 데이터 폴더에 쓸 수 있는지 확인한 후 다시 시도하세요.",
50 "a0315d43e8e5be7e": "허용",
51 "2ec823ca24387055": "차단",
52 + "709219ff9ff49a4f": "{origin}에서 위치 정보에 접근하려고 합니다",
53 "8fc0b116123fb50b": "{origin}에서 클립보드에 복사된 텍스트와 이미지를 보려고 합니다",
54 "c0f756221736393f": "미리 보기 · {title}",
55 "6994444f4fec4070": "브라우저 미리 보기",
apps/desktop/src/i18n/translations/pt-BR.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "O T3 Code não conseguiu salvar esta aprovação, então a página continua bloqueada. Verifique se o disco não está cheio e se a pasta de dados permite gravação e tente novamente.",
50 "a0315d43e8e5be7e": "Permitir",
51 "2ec823ca24387055": "Bloquear",
52 + "709219ff9ff49a4f": "{origin} quer saber sua localização",
53 "8fc0b116123fb50b": "{origin} quer ver textos e imagens copiados para a área de transferência",
54 "c0f756221736393f": "Pré-visualização · {title}",
55 "6994444f4fec4070": "Pré-visualização do navegador",
apps/desktop/src/i18n/translations/ru.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code не удалось сохранить это разрешение, поэтому страница остаётся заблокированной. Убедитесь, что диск не заполнен, а папка данных доступна для записи, и повторите попытку.",
50 "a0315d43e8e5be7e": "Разрешить",
51 "2ec823ca24387055": "Блокировать",
52 + "709219ff9ff49a4f": "{origin} запрашивает ваше местоположение",
53 "8fc0b116123fb50b": "{origin} хочет видеть текст и изображения, скопированные в буфер обмена",
54 "c0f756221736393f": "Предпросмотр · {title}",
55 "6994444f4fec4070": "Предпросмотр в браузере",
apps/desktop/src/i18n/translations/sv.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code kunde inte spara det här godkännandet, så sidan förblir blockerad. Kontrollera att disken inte är full och att datamappen är skrivbar och försök sedan igen.",
50 "a0315d43e8e5be7e": "Tillåt",
51 "2ec823ca24387055": "Blockera",
52 + "709219ff9ff49a4f": "{origin} vill veta var du befinner dig",
53 "8fc0b116123fb50b": "{origin} vill se text och bilder som kopierats till urklipp",
54 "c0f756221736393f": "Förhandsvisning · {title}",
55 "6994444f4fec4070": "Förhandsvisning i webbläsaren",
apps/desktop/src/i18n/translations/zh.json
+1
@@ -49,6 +49,7 @@
49 "935a340963533dcf": "T3 Code 无法保存此次批准,因此页面仍被阻止。请检查磁盘空间和数据目录的写入权限后重试。",
50 "a0315d43e8e5be7e": "允许",
51 "2ec823ca24387055": "阻止",
52 + "709219ff9ff49a4f": "{origin} 想要获取你的位置",
53 "8fc0b116123fb50b": "{origin} 想查看复制到剪贴板的文字和图片",
54 "c0f756221736393f": "预览 · {title}",
55 "6994444f4fec4070": "浏览器预览",
apps/desktop/src/preview/AnnotationKeyboard.test.ts
+9
@@ -5,6 +5,7 @@ import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts";
5 const keyboardEvent = (
6 overrides: Partial<Parameters<typeof resolveAnnotationSubmission>[0]> = {},
7 ) => ({
8 + isTrusted: true,
9 key: "Enter",
10 metaKey: false,
11 ctrlKey: false,
@@ -14,6 +15,14 @@ const keyboardEvent = (
15 });
16
17 describe("resolveAnnotationSubmission", () => {
18 + it("requires trusted input to attach or send an annotation", () => {
19 + expect(resolveAnnotationSubmission(keyboardEvent(), true)).toBe("attach");
20 + expect(resolveAnnotationSubmission(keyboardEvent({ metaKey: true }), true)).toBe("send");
21 + expect(resolveAnnotationSubmission(keyboardEvent({ isTrusted: false }), true)).toBeNull();
22 + expect(
23 + resolveAnnotationSubmission(keyboardEvent({ isTrusted: false, metaKey: true }), true),
24 + ).toBeNull();
25 + });
26 it("leaves Shift+Enter and composition events available for editing", () => {
27 expect(resolveAnnotationSubmission(keyboardEvent({ shiftKey: true }), true)).toBeNull();
28 expect(resolveAnnotationSubmission(keyboardEvent({ isComposing: true }), true)).toBeNull();
apps/desktop/src/preview/AnnotationKeyboard.ts
+2 -1
@@ -1,6 +1,7 @@
1 import type { PreviewAnnotationSubmission } from "@t3tools/contracts";
2
3 interface AnnotationKeyboardEvent {
4 + readonly isTrusted: boolean;
5 readonly key: string;
6 readonly metaKey: boolean;
7 readonly ctrlKey: boolean;
@@ -12,6 +13,6 @@ export function resolveAnnotationSubmission(
13 event: AnnotationKeyboardEvent,
14 canSend: boolean,
15 ): PreviewAnnotationSubmission | null {
15 - if (event.key !== "Enter" || event.shiftKey || event.isComposing) return null;
16 + if (!event.isTrusted || event.key !== "Enter" || event.shiftKey || event.isComposing) return null;
17 return event.metaKey || event.ctrlKey ? (canSend ? "send" : null) : "attach";
18 }
apps/desktop/src/preview/BrowserSession.test.ts
+23 -20
@@ -287,7 +287,6 @@ describe("BrowserSession", () => {
287
288 for (const permission of [
289 "clipboard-sanitized-write",
290 - "geolocation",
290 "fullscreen",
291 "pointerLock",
292 "loopback-network",
@@ -350,7 +349,13 @@ describe("BrowserSession", () => {
349 }).pipe(Effect.provide(layer)),
350 );
351
353 - it.effect("asks once per origin before a page reads the clipboard", () =>
352 + it.effect.each([
353 + {
354 + permission: "clipboard-read",
355 + description: "see text and images copied to the clipboard",
356 + },
357 + { permission: "geolocation", description: "know your location" },
358 + ])("asks once per origin before granting $permission", ({ permission, description }) =>
359 Effect.gen(function* () {
360 const browserSessions = yield* BrowserSession.BrowserSession;
361 const partition = yield* browserSessions.getPartition("scope-a");
@@ -362,39 +367,37 @@ describe("BrowserSession", () => {
367 assert.isFunction(requestHandler);
368 assert.isFunction(checkHandler);
369
365 - const readClipboard = (requestingUrl: string) =>
370 + const requestPermission = (requestingUrl: string) =>
371 Effect.callback<boolean>((resume) => {
367 - requestHandler(
368 - null,
369 - "clipboard-read",
370 - (granted: boolean) => resume(Effect.succeed(granted)),
371 - { requestingUrl, isMainFrame: true },
372 - );
372 + requestHandler(null, permission, (granted: boolean) => resume(Effect.succeed(granted)), {
373 + requestingUrl,
374 + isMainFrame: true,
375 + });
376 });
374 - const checkClipboard = (origin: string): boolean =>
375 - checkHandler(null, "clipboard-read", origin, {}) as boolean;
377 + const checkPermission = (origin: string): boolean =>
378 + checkHandler(null, permission, origin, {}) as boolean;
379
380 showMessageBox.mockReset();
381 showMessageBox.mockReturnValueOnce(0).mockReturnValueOnce(1);
382
380 - assert.isFalse(checkClipboard("https://allowed.test"));
381 - assert.isTrue(yield* readClipboard("https://allowed.test/page"));
383 + assert.isFalse(checkPermission("https://allowed.test"));
384 + assert.isTrue(yield* requestPermission("https://allowed.test/page"));
385 assert.strictEqual(showMessageBox.mock.calls.length, 1);
386 assert.strictEqual(
387 showMessageBox.mock.calls[0]?.[0].message,
385 - "https://allowed.test wants to see text and images copied to the clipboard",
388 + `https://allowed.test wants to ${description}`,
389 );
390 assert.deepStrictEqual(showMessageBox.mock.calls[0]?.[0].buttons, ["Allow", "Block"]);
391 // Enter must not accept a prompt the page raised while the user was typing.
392 assert.strictEqual(showMessageBox.mock.calls[0]?.[0].defaultId, 1);
393
391 - assert.isTrue(yield* readClipboard("https://allowed.test/other"));
392 - assert.isTrue(checkClipboard("https://allowed.test"));
394 + assert.isTrue(yield* requestPermission("https://allowed.test/other"));
395 + assert.isTrue(checkPermission("https://allowed.test"));
396
394 - assert.isFalse(yield* readClipboard("https://blocked.test/"));
395 - assert.isFalse(yield* readClipboard("https://blocked.test/again"));
396 - assert.isFalse(checkClipboard("https://blocked.test"));
397 - assert.isTrue(checkClipboard("https://allowed.test"));
397 + assert.isFalse(yield* requestPermission("https://blocked.test/"));
398 + assert.isFalse(yield* requestPermission("https://blocked.test/again"));
399 + assert.isFalse(checkPermission("https://blocked.test"));
400 + assert.isTrue(checkPermission("https://allowed.test"));
401 assert.strictEqual(showMessageBox.mock.calls.length, 2);
402 }).pipe(Effect.provide(layer)),
403 );
apps/desktop/src/preview/BrowserSession.ts
+26 -14
@@ -30,7 +30,6 @@ export type BrowserSessionPartitionNamespace = "profile";
30 // Electron's clipboard API uses clipboard-sanitized-write and checks both permission handlers.
31 const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
32 "clipboard-sanitized-write",
33 - "geolocation",
33 // DesktopWindow confines HTML fullscreen to the guest's webview.
34 "fullscreen",
35 "pointerLock",
@@ -301,7 +300,7 @@ export const make = Effect.gen(function* BrowserSessionMake() {
300 message: prompt.message,
301 ...(prompt.detail === undefined ? {} : { detail: prompt.detail }),
302 },
304 - previewHostWindow(requester),
303 + platform === "win32" ? undefined : previewHostWindow(requester),
304 )
305 .pipe(
306 Effect.map(({ response }): boolean | undefined => response === 0),
@@ -607,19 +606,25 @@ export const make = Effect.gen(function* BrowserSessionMake() {
606 return Effect.try({
607 try: () => {
608 const browserSession = session.fromPartition(partition);
610 - // Like Chrome, clipboard reads ask once per origin; both answers last for the session.
611 - const clipboardReadDecisions = new Map<string, boolean>();
612 - const confirmClipboardRead = (
609 + // Location and clipboard decisions are remembered separately for each origin.
610 + const permissionDecisions = {
611 + "clipboard-read": new Map<string, boolean>(),
612 + geolocation: new Map<string, boolean>(),
613 + };
614 + const confirmOriginPermission = (
615 requester: WebContents,
616 + permission: keyof typeof permissionDecisions,
617 rawUrl: string | undefined,
618 callback: (granted: boolean) => void,
619 ): void => {
620 const origin = permissionOrigin(rawUrl);
621 if (origin === null) {
622 + // A frame URL such as about:srcdoc cannot establish whether its origin is inherited or opaque.
623 callback(false);
624 return;
625 }
622 - const remembered = clipboardReadDecisions.get(origin);
626 + const decisions = permissionDecisions[permission];
627 + const remembered = decisions.get(origin);
628 if (remembered !== undefined) {
629 callback(remembered);
630 return;
@@ -631,12 +636,17 @@ export const make = Effect.gen(function* BrowserSessionMake() {
636 m(msg("Allow", { $context: "button, grants a site permission" })),
637 m(msg("Block", { $context: "button, denies a site permission" })),
638 ],
634 - message: m(msg("{origin} wants to see text and images copied to the clipboard"), {
635 - origin: truncateForPrompt(origin),
636 - }),
639 + message:
640 + permission === "geolocation"
641 + ? m(msg("{origin} wants to know your location"), {
642 + origin: truncateForPrompt(origin),
643 + })
644 + : m(msg("{origin} wants to see text and images copied to the clipboard"), {
645 + origin: truncateForPrompt(origin),
646 + }),
647 },
648 (answer) => {
639 - if (answer !== undefined) clipboardReadDecisions.set(origin, answer);
649 + if (answer !== undefined) decisions.set(origin, answer);
650 callback(answer === true);
651 },
652 );
@@ -652,9 +662,10 @@ export const make = Effect.gen(function* BrowserSessionMake() {
662 );
663 return;
664 }
655 - if (permission === "clipboard-read") {
656 - confirmClipboardRead(
665 + if (permission === "clipboard-read" || permission === "geolocation") {
666 + confirmOriginPermission(
667 webContents,
668 + permission,
669 "requestingUrl" in details ? details.requestingUrl : undefined,
670 callback,
671 );
@@ -664,8 +675,9 @@ export const make = Effect.gen(function* BrowserSessionMake() {
675 },
676 );
677 browserSession.setPermissionCheckHandler((_webContents, permission, requestingOrigin) =>
667 - permission === "clipboard-read"
668 - ? clipboardReadDecisions.get(permissionOrigin(requestingOrigin) ?? "") === true
678 + permission === "clipboard-read" || permission === "geolocation"
679 + ? permissionDecisions[permission].get(permissionOrigin(requestingOrigin) ?? "") ===
680 + true
681 : ALLOWED_PREVIEW_PERMISSIONS.has(permission),
682 );
683 browserSession.webRequest.onBeforeSendHeaders(
apps/desktop/src/preview/PickPreload.test.ts
+10
@@ -124,6 +124,7 @@ it.each([
124 .spyOn(card, "getBoundingClientRect")
125 .mockImplementation(() => (card.isConnected ? pickedRect : new DOMRect()));
126 document.elementsFromPoint = () => [card];
127 + using listeners = vi.spyOn(HTMLButtonElement.prototype, "addEventListener");
128 const shadowRoot = startAnnotation();
129
130 card.dispatchEvent(
@@ -137,6 +138,15 @@ it.each([
138 );
139 if (!attach) throw new Error("Attach button not found");
140 attach.click();
141 + expect(attach.disabled).toBe(false);
142 + expect(ipcSend.calls.some(([channel]) => channel === ELEMENT_PICKED_CHANNEL)).toBe(false);
143 + const listenerIndex = listeners.mock.contexts.findIndex(
144 + (target, index) => target === attach && listeners.mock.calls[index]?.[0] === "click",
145 + );
146 + const listener = listeners.mock.calls[listenerIndex]?.[1];
147 + if (typeof listener !== "function") throw new Error("Attach click listener not found");
148 + // The DOM test environment has no native input source.
149 + listener.call(attach, { isTrusted: true } as MouseEvent);
150
151 await vi.waitFor(() =>
152 expect(ipcSend.calls.some(([channel]) => channel === ELEMENT_PICKED_CHANNEL)).toBe(true),
apps/desktop/src/preview/PickPreload.ts
+3 -1
@@ -1776,7 +1776,9 @@ function startAnnotation(
1776 teardown(true);
1777 });
1778 };
1779 - submit.addEventListener("click", () => submitAnnotation("attach"));
1779 + submit.addEventListener("click", (event) => {
1780 + if (event.isTrusted) submitAnnotation("attach");
1781 + });
1782 const handleOverlayKey = (event: KeyboardEvent): void => {
1783 if (event.type === "keyup") onVoiceKeyUp(event);
1784 if (event.type !== "keydown") return;