diff --git a/apps/desktop/src/i18n/translations/de.json b/apps/desktop/src/i18n/translations/de.json index bd128da18cd16..253643f19b9b9 100644 --- a/apps/desktop/src/i18n/translations/de.json +++ b/apps/desktop/src/i18n/translations/de.json @@ -49,6 +49,7 @@ "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.", "a0315d43e8e5be7e": "Erlauben", "2ec823ca24387055": "Blockieren", + "709219ff9ff49a4f": "{origin} möchte deinen Standort erfahren", "8fc0b116123fb50b": "{origin} möchte in die Zwischenablage kopierte Texte und Bilder sehen", "c0f756221736393f": "Vorschau · {title}", "6994444f4fec4070": "Browservorschau", diff --git a/apps/desktop/src/i18n/translations/en.json b/apps/desktop/src/i18n/translations/en.json index ad77a1a07a9a3..833aea465a406 100644 --- a/apps/desktop/src/i18n/translations/en.json +++ b/apps/desktop/src/i18n/translations/en.json @@ -49,6 +49,7 @@ "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.", "a0315d43e8e5be7e": "Allow", "2ec823ca24387055": "Block", + "709219ff9ff49a4f": "{origin} wants to know your location", "8fc0b116123fb50b": "{origin} wants to see text and images copied to the clipboard", "c0f756221736393f": "Preview · {title}", "6994444f4fec4070": "Browser preview", diff --git a/apps/desktop/src/i18n/translations/es.json b/apps/desktop/src/i18n/translations/es.json index 0b3243ebe918b..4a45d87e968b5 100644 --- a/apps/desktop/src/i18n/translations/es.json +++ b/apps/desktop/src/i18n/translations/es.json @@ -49,6 +49,7 @@ "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.", "a0315d43e8e5be7e": "Permitir", "2ec823ca24387055": "Bloquear", + "709219ff9ff49a4f": "{origin} quiere conocer tu ubicación", "8fc0b116123fb50b": "{origin} quiere ver el texto y las imágenes copiados al portapapeles", "c0f756221736393f": "Vista previa · {title}", "6994444f4fec4070": "Vista previa del navegador", diff --git a/apps/desktop/src/i18n/translations/fr.json b/apps/desktop/src/i18n/translations/fr.json index a0dcf1bd13ac3..5c31d472f5d70 100644 --- a/apps/desktop/src/i18n/translations/fr.json +++ b/apps/desktop/src/i18n/translations/fr.json @@ -49,6 +49,7 @@ "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.", "a0315d43e8e5be7e": "Autoriser", "2ec823ca24387055": "Bloquer", + "709219ff9ff49a4f": "{origin} souhaite connaître votre position", "8fc0b116123fb50b": "{origin} veut voir le texte et les images copiés dans le presse-papiers", "c0f756221736393f": "Aperçu · {title}", "6994444f4fec4070": "Aperçu du navigateur", diff --git a/apps/desktop/src/i18n/translations/ja.json b/apps/desktop/src/i18n/translations/ja.json index 93553bbf1a743..867b271262724 100644 --- a/apps/desktop/src/i18n/translations/ja.json +++ b/apps/desktop/src/i18n/translations/ja.json @@ -49,6 +49,7 @@ "935a340963533dcf": "T3 Code はこの承認を保存できなかったため、ページはブロックされたままです。ディスクがいっぱいでないこと、データフォルダーに書き込めることを確認してから、もう一度お試しください。", "a0315d43e8e5be7e": "許可", "2ec823ca24387055": "ブロック", + "709219ff9ff49a4f": "{origin} が位置情報へのアクセスを求めています", "8fc0b116123fb50b": "{origin} がクリップボードにコピーされたテキストと画像の表示を求めています", "c0f756221736393f": "プレビュー · {title}", "6994444f4fec4070": "ブラウザープレビュー", diff --git a/apps/desktop/src/i18n/translations/ko.json b/apps/desktop/src/i18n/translations/ko.json index aac215f3a63d1..7c15523447278 100644 --- a/apps/desktop/src/i18n/translations/ko.json +++ b/apps/desktop/src/i18n/translations/ko.json @@ -49,6 +49,7 @@ "935a340963533dcf": "T3 Code가 이 승인을 저장하지 못해 페이지가 계속 차단됩니다. 디스크가 가득 차지 않았는지, 데이터 폴더에 쓸 수 있는지 확인한 후 다시 시도하세요.", "a0315d43e8e5be7e": "허용", "2ec823ca24387055": "차단", + "709219ff9ff49a4f": "{origin}에서 위치 정보에 접근하려고 합니다", "8fc0b116123fb50b": "{origin}에서 클립보드에 복사된 텍스트와 이미지를 보려고 합니다", "c0f756221736393f": "미리 보기 · {title}", "6994444f4fec4070": "브라우저 미리 보기", diff --git a/apps/desktop/src/i18n/translations/pt-BR.json b/apps/desktop/src/i18n/translations/pt-BR.json index 78e635076cf72..4f3460638c22a 100644 --- a/apps/desktop/src/i18n/translations/pt-BR.json +++ b/apps/desktop/src/i18n/translations/pt-BR.json @@ -49,6 +49,7 @@ "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.", "a0315d43e8e5be7e": "Permitir", "2ec823ca24387055": "Bloquear", + "709219ff9ff49a4f": "{origin} quer saber sua localização", "8fc0b116123fb50b": "{origin} quer ver textos e imagens copiados para a área de transferência", "c0f756221736393f": "Pré-visualização · {title}", "6994444f4fec4070": "Pré-visualização do navegador", diff --git a/apps/desktop/src/i18n/translations/ru.json b/apps/desktop/src/i18n/translations/ru.json index deb40ac5292c2..3e8f2fa9fed06 100644 --- a/apps/desktop/src/i18n/translations/ru.json +++ b/apps/desktop/src/i18n/translations/ru.json @@ -49,6 +49,7 @@ "935a340963533dcf": "T3 Code не удалось сохранить это разрешение, поэтому страница остаётся заблокированной. Убедитесь, что диск не заполнен, а папка данных доступна для записи, и повторите попытку.", "a0315d43e8e5be7e": "Разрешить", "2ec823ca24387055": "Блокировать", + "709219ff9ff49a4f": "{origin} запрашивает ваше местоположение", "8fc0b116123fb50b": "{origin} хочет видеть текст и изображения, скопированные в буфер обмена", "c0f756221736393f": "Предпросмотр · {title}", "6994444f4fec4070": "Предпросмотр в браузере", diff --git a/apps/desktop/src/i18n/translations/sv.json b/apps/desktop/src/i18n/translations/sv.json index aa30b26073b39..e8ac486b64242 100644 --- a/apps/desktop/src/i18n/translations/sv.json +++ b/apps/desktop/src/i18n/translations/sv.json @@ -49,6 +49,7 @@ "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.", "a0315d43e8e5be7e": "Tillåt", "2ec823ca24387055": "Blockera", + "709219ff9ff49a4f": "{origin} vill veta var du befinner dig", "8fc0b116123fb50b": "{origin} vill se text och bilder som kopierats till urklipp", "c0f756221736393f": "Förhandsvisning · {title}", "6994444f4fec4070": "Förhandsvisning i webbläsaren", diff --git a/apps/desktop/src/i18n/translations/zh.json b/apps/desktop/src/i18n/translations/zh.json index f8c6a6e6be217..ecee6a4ab13ae 100644 --- a/apps/desktop/src/i18n/translations/zh.json +++ b/apps/desktop/src/i18n/translations/zh.json @@ -49,6 +49,7 @@ "935a340963533dcf": "T3 Code 无法保存此次批准,因此页面仍被阻止。请检查磁盘空间和数据目录的写入权限后重试。", "a0315d43e8e5be7e": "允许", "2ec823ca24387055": "阻止", + "709219ff9ff49a4f": "{origin} 想要获取你的位置", "8fc0b116123fb50b": "{origin} 想查看复制到剪贴板的文字和图片", "c0f756221736393f": "预览 · {title}", "6994444f4fec4070": "浏览器预览", diff --git a/apps/desktop/src/preview/AnnotationKeyboard.test.ts b/apps/desktop/src/preview/AnnotationKeyboard.test.ts index 11fb9100e398f..945cf778a240d 100644 --- a/apps/desktop/src/preview/AnnotationKeyboard.test.ts +++ b/apps/desktop/src/preview/AnnotationKeyboard.test.ts @@ -5,6 +5,7 @@ import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts"; const keyboardEvent = ( overrides: Partial[0]> = {}, ) => ({ + isTrusted: true, key: "Enter", metaKey: false, ctrlKey: false, @@ -14,6 +15,14 @@ const keyboardEvent = ( }); describe("resolveAnnotationSubmission", () => { + it("requires trusted input to attach or send an annotation", () => { + expect(resolveAnnotationSubmission(keyboardEvent(), true)).toBe("attach"); + expect(resolveAnnotationSubmission(keyboardEvent({ metaKey: true }), true)).toBe("send"); + expect(resolveAnnotationSubmission(keyboardEvent({ isTrusted: false }), true)).toBeNull(); + expect( + resolveAnnotationSubmission(keyboardEvent({ isTrusted: false, metaKey: true }), true), + ).toBeNull(); + }); it("leaves Shift+Enter and composition events available for editing", () => { expect(resolveAnnotationSubmission(keyboardEvent({ shiftKey: true }), true)).toBeNull(); expect(resolveAnnotationSubmission(keyboardEvent({ isComposing: true }), true)).toBeNull(); diff --git a/apps/desktop/src/preview/AnnotationKeyboard.ts b/apps/desktop/src/preview/AnnotationKeyboard.ts index 8b935bfbec1d4..2f598c9c4c051 100644 --- a/apps/desktop/src/preview/AnnotationKeyboard.ts +++ b/apps/desktop/src/preview/AnnotationKeyboard.ts @@ -1,6 +1,7 @@ import type { PreviewAnnotationSubmission } from "@t3tools/contracts"; interface AnnotationKeyboardEvent { + readonly isTrusted: boolean; readonly key: string; readonly metaKey: boolean; readonly ctrlKey: boolean; @@ -12,6 +13,6 @@ export function resolveAnnotationSubmission( event: AnnotationKeyboardEvent, canSend: boolean, ): PreviewAnnotationSubmission | null { - if (event.key !== "Enter" || event.shiftKey || event.isComposing) return null; + if (!event.isTrusted || event.key !== "Enter" || event.shiftKey || event.isComposing) return null; return event.metaKey || event.ctrlKey ? (canSend ? "send" : null) : "attach"; } diff --git a/apps/desktop/src/preview/BrowserSession.test.ts b/apps/desktop/src/preview/BrowserSession.test.ts index 9a9be6213c39a..7d2b3fe0e9fa0 100644 --- a/apps/desktop/src/preview/BrowserSession.test.ts +++ b/apps/desktop/src/preview/BrowserSession.test.ts @@ -287,7 +287,6 @@ describe("BrowserSession", () => { for (const permission of [ "clipboard-sanitized-write", - "geolocation", "fullscreen", "pointerLock", "loopback-network", @@ -350,7 +349,13 @@ describe("BrowserSession", () => { }).pipe(Effect.provide(layer)), ); - it.effect("asks once per origin before a page reads the clipboard", () => + it.effect.each([ + { + permission: "clipboard-read", + description: "see text and images copied to the clipboard", + }, + { permission: "geolocation", description: "know your location" }, + ])("asks once per origin before granting $permission", ({ permission, description }) => Effect.gen(function* () { const browserSessions = yield* BrowserSession.BrowserSession; const partition = yield* browserSessions.getPartition("scope-a"); @@ -362,39 +367,37 @@ describe("BrowserSession", () => { assert.isFunction(requestHandler); assert.isFunction(checkHandler); - const readClipboard = (requestingUrl: string) => + const requestPermission = (requestingUrl: string) => Effect.callback((resume) => { - requestHandler( - null, - "clipboard-read", - (granted: boolean) => resume(Effect.succeed(granted)), - { requestingUrl, isMainFrame: true }, - ); + requestHandler(null, permission, (granted: boolean) => resume(Effect.succeed(granted)), { + requestingUrl, + isMainFrame: true, + }); }); - const checkClipboard = (origin: string): boolean => - checkHandler(null, "clipboard-read", origin, {}) as boolean; + const checkPermission = (origin: string): boolean => + checkHandler(null, permission, origin, {}) as boolean; showMessageBox.mockReset(); showMessageBox.mockReturnValueOnce(0).mockReturnValueOnce(1); - assert.isFalse(checkClipboard("https://allowed.test")); - assert.isTrue(yield* readClipboard("https://allowed.test/page")); + assert.isFalse(checkPermission("https://allowed.test")); + assert.isTrue(yield* requestPermission("https://allowed.test/page")); assert.strictEqual(showMessageBox.mock.calls.length, 1); assert.strictEqual( showMessageBox.mock.calls[0]?.[0].message, - "https://allowed.test wants to see text and images copied to the clipboard", + `https://allowed.test wants to ${description}`, ); assert.deepStrictEqual(showMessageBox.mock.calls[0]?.[0].buttons, ["Allow", "Block"]); // Enter must not accept a prompt the page raised while the user was typing. assert.strictEqual(showMessageBox.mock.calls[0]?.[0].defaultId, 1); - assert.isTrue(yield* readClipboard("https://allowed.test/other")); - assert.isTrue(checkClipboard("https://allowed.test")); + assert.isTrue(yield* requestPermission("https://allowed.test/other")); + assert.isTrue(checkPermission("https://allowed.test")); - assert.isFalse(yield* readClipboard("https://blocked.test/")); - assert.isFalse(yield* readClipboard("https://blocked.test/again")); - assert.isFalse(checkClipboard("https://blocked.test")); - assert.isTrue(checkClipboard("https://allowed.test")); + assert.isFalse(yield* requestPermission("https://blocked.test/")); + assert.isFalse(yield* requestPermission("https://blocked.test/again")); + assert.isFalse(checkPermission("https://blocked.test")); + assert.isTrue(checkPermission("https://allowed.test")); assert.strictEqual(showMessageBox.mock.calls.length, 2); }).pipe(Effect.provide(layer)), ); diff --git a/apps/desktop/src/preview/BrowserSession.ts b/apps/desktop/src/preview/BrowserSession.ts index c3a189f08a6dd..d247fcbcd8266 100644 --- a/apps/desktop/src/preview/BrowserSession.ts +++ b/apps/desktop/src/preview/BrowserSession.ts @@ -30,7 +30,6 @@ export type BrowserSessionPartitionNamespace = "profile"; // Electron's clipboard API uses clipboard-sanitized-write and checks both permission handlers. const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet = new Set([ "clipboard-sanitized-write", - "geolocation", // DesktopWindow confines HTML fullscreen to the guest's webview. "fullscreen", "pointerLock", @@ -301,7 +300,7 @@ export const make = Effect.gen(function* BrowserSessionMake() { message: prompt.message, ...(prompt.detail === undefined ? {} : { detail: prompt.detail }), }, - previewHostWindow(requester), + platform === "win32" ? undefined : previewHostWindow(requester), ) .pipe( Effect.map(({ response }): boolean | undefined => response === 0), @@ -607,19 +606,25 @@ export const make = Effect.gen(function* BrowserSessionMake() { return Effect.try({ try: () => { const browserSession = session.fromPartition(partition); - // Like Chrome, clipboard reads ask once per origin; both answers last for the session. - const clipboardReadDecisions = new Map(); - const confirmClipboardRead = ( + // Location and clipboard decisions are remembered separately for each origin. + const permissionDecisions = { + "clipboard-read": new Map(), + geolocation: new Map(), + }; + const confirmOriginPermission = ( requester: WebContents, + permission: keyof typeof permissionDecisions, rawUrl: string | undefined, callback: (granted: boolean) => void, ): void => { const origin = permissionOrigin(rawUrl); if (origin === null) { + // A frame URL such as about:srcdoc cannot establish whether its origin is inherited or opaque. callback(false); return; } - const remembered = clipboardReadDecisions.get(origin); + const decisions = permissionDecisions[permission]; + const remembered = decisions.get(origin); if (remembered !== undefined) { callback(remembered); return; @@ -631,12 +636,17 @@ export const make = Effect.gen(function* BrowserSessionMake() { m(msg("Allow", { $context: "button, grants a site permission" })), m(msg("Block", { $context: "button, denies a site permission" })), ], - message: m(msg("{origin} wants to see text and images copied to the clipboard"), { - origin: truncateForPrompt(origin), - }), + message: + permission === "geolocation" + ? m(msg("{origin} wants to know your location"), { + origin: truncateForPrompt(origin), + }) + : m(msg("{origin} wants to see text and images copied to the clipboard"), { + origin: truncateForPrompt(origin), + }), }, (answer) => { - if (answer !== undefined) clipboardReadDecisions.set(origin, answer); + if (answer !== undefined) decisions.set(origin, answer); callback(answer === true); }, ); @@ -652,9 +662,10 @@ export const make = Effect.gen(function* BrowserSessionMake() { ); return; } - if (permission === "clipboard-read") { - confirmClipboardRead( + if (permission === "clipboard-read" || permission === "geolocation") { + confirmOriginPermission( webContents, + permission, "requestingUrl" in details ? details.requestingUrl : undefined, callback, ); @@ -664,8 +675,9 @@ export const make = Effect.gen(function* BrowserSessionMake() { }, ); browserSession.setPermissionCheckHandler((_webContents, permission, requestingOrigin) => - permission === "clipboard-read" - ? clipboardReadDecisions.get(permissionOrigin(requestingOrigin) ?? "") === true + permission === "clipboard-read" || permission === "geolocation" + ? permissionDecisions[permission].get(permissionOrigin(requestingOrigin) ?? "") === + true : ALLOWED_PREVIEW_PERMISSIONS.has(permission), ); browserSession.webRequest.onBeforeSendHeaders( diff --git a/apps/desktop/src/preview/PickPreload.test.ts b/apps/desktop/src/preview/PickPreload.test.ts index abf9421985f21..ce1dc09557f74 100644 --- a/apps/desktop/src/preview/PickPreload.test.ts +++ b/apps/desktop/src/preview/PickPreload.test.ts @@ -124,6 +124,7 @@ it.each([ .spyOn(card, "getBoundingClientRect") .mockImplementation(() => (card.isConnected ? pickedRect : new DOMRect())); document.elementsFromPoint = () => [card]; + using listeners = vi.spyOn(HTMLButtonElement.prototype, "addEventListener"); const shadowRoot = startAnnotation(); card.dispatchEvent( @@ -137,6 +138,15 @@ it.each([ ); if (!attach) throw new Error("Attach button not found"); attach.click(); + expect(attach.disabled).toBe(false); + expect(ipcSend.calls.some(([channel]) => channel === ELEMENT_PICKED_CHANNEL)).toBe(false); + const listenerIndex = listeners.mock.contexts.findIndex( + (target, index) => target === attach && listeners.mock.calls[index]?.[0] === "click", + ); + const listener = listeners.mock.calls[listenerIndex]?.[1]; + if (typeof listener !== "function") throw new Error("Attach click listener not found"); + // The DOM test environment has no native input source. + listener.call(attach, { isTrusted: true } as MouseEvent); await vi.waitFor(() => expect(ipcSend.calls.some(([channel]) => channel === ELEMENT_PICKED_CHANNEL)).toBe(true), diff --git a/apps/desktop/src/preview/PickPreload.ts b/apps/desktop/src/preview/PickPreload.ts index 14ae5b16f33d6..f2b2bf773ab17 100644 --- a/apps/desktop/src/preview/PickPreload.ts +++ b/apps/desktop/src/preview/PickPreload.ts @@ -1776,7 +1776,9 @@ function startAnnotation( teardown(true); }); }; - submit.addEventListener("click", () => submitAnnotation("attach")); + submit.addEventListener("click", (event) => { + if (event.isTrusted) submitAnnotation("attach"); + }); const handleOverlayKey = (event: KeyboardEvent): void => { if (event.type === "keyup") onVoiceKeyUp(event); if (event.type !== "keydown") return;