1675d77b27bc
reject synthetic TOTP selector keys (v5.3.27)
- time
- 2026-11-22 20:36 UTC · 5 days ago
- machine
- Junes-MacBook-Pro.local
- agent
- gpt-5.6-sol
- session
- remediate interim audit findings
- parent
- f80e84ebbcbb
↓ peach-browser-1675d77b.tar.gzatlas at this save
files changed5 files
manifest.firefox.json+1 −1manifest.json+1 −1package.json+1 −1src/content/inject.keyguard.test.ts+123 −3src/content/inject.ts+1 −0manifest.firefox.json+1 −1
@@ -1,7 +1,7 @@11 {22 "manifest_version": 3,33 "name": "Peach Password Manager",4- "version": "5.3.26",4+ "version": "5.3.27",55 "description": "Zero-knowledge password manager",66 "browser_specific_settings": {77 "gecko": {manifest.json+1 −1
@@ -2,7 +2,7 @@22 "manifest_version": 3,33 "minimum_chrome_version": "116",44 "name": "Peach Password Manager",5- "version": "5.3.26",5+ "version": "5.3.27",66 "description": "Zero-knowledge password manager",77 "action": {88 "default_popup": "src/popup/index.html",package.json+1 −1
@@ -1,6 +1,6 @@11 {22 "name": "peach",3- "version": "5.3.26",3+ "version": "5.3.27",44 "description": "Zero-knowledge password manager",55 "license": "GPL-3.0-only",66 "type": "module",src/content/inject.keyguard.test.ts+123 −3
@@ -2,12 +2,13 @@22 33 import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";44 5-// PCH-01-007: the three document-level keydown handlers inside the inline6-// selector must ignore page-synthesised KeyboardEvents (isTrusted === false),5+// PCH-01-007: document-level keydown handlers inside inline selectors must6+// ignore page-synthesised KeyboardEvents (isTrusted === false),77 // so a host page cannot script selection + fill without a real keypress.88 99 describe("PCH-01-007 — inject keydown handlers gate on e.isTrusted", () => {1010 let showAutofillSelector: typeof import("./inject").showAutofillSelector;11+ let showTOTPSelector: typeof import("./inject").showTOTPSelector;1112 let cleanup: (() => void) | null = null;1213 1314 beforeEach(async () => {@@ -22,7 +23,7 @@2223 }2324 (globalThis as unknown as { ResizeObserver: unknown }).ResizeObserver = NoopObserver;2425 (globalThis as unknown as { IntersectionObserver: unknown }).IntersectionObserver = NoopObserver;25- ({ showAutofillSelector } = await import("./inject"));26+ ({ showAutofillSelector, showTOTPSelector } = await import("./inject"));2627 });2728 2829 afterEach(() => {@@ -66,5 +67,124 @@6667 // A page-dispatched printable key must not drive selection/fill.6768 document.dispatchEvent(new KeyboardEvent("keydown", { key: "a", bubbles: true }));6869 expect(onSelect).not.toHaveBeenCalled();70+ });71+72+ it("keeps the TOTP selection unchanged after an untrusted arrow key", () => {73+ const input = document.createElement("input");74+ document.body.appendChild(input);75+ const originalAttachShadow = Element.prototype.attachShadow;76+ let closedShadow: ShadowRoot | null = null;77+ const attachSpy = vi.spyOn(Element.prototype, "attachShadow").mockImplementation(function (78+ this: Element,79+ init: ShadowRootInit,80+ ) {81+ closedShadow = originalAttachShadow.call(this, init);82+ return closedShadow;83+ });84+ const scrollIntoView = vi.fn();85+ Object.defineProperty(HTMLElement.prototype, "scrollIntoView", {86+ configurable: true,87+ value: scrollIntoView,88+ });89+90+ try {91+ cleanup = showTOTPSelector(92+ input,93+ [94+ { id: "1", title: "GitHub", username: "june", hasTotp: true },95+ { id: "2", title: "GitLab", username: "june", hasTotp: true },96+ ],97+ vi.fn(),98+ );99+ expect(input.nextElementSibling?.shadowRoot).toBeNull();100+101+ document.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }));102+103+ expect((closedShadow as ShadowRoot | null)?.querySelector(".entry.focused")).toBeNull();104+ expect(scrollIntoView).not.toHaveBeenCalled();105+ } finally {106+ attachSpy.mockRestore();107+ delete (HTMLElement.prototype as { scrollIntoView?: unknown }).scrollIntoView;108+ }109+ });110+111+ it("does not fill or copy after an untrusted TOTP Enter key", () => {112+ const input = document.createElement("input");113+ document.body.appendChild(input);114+ const copy = vi.fn(() => Promise.resolve());115+ const originalClipboard = Object.getOwnPropertyDescriptor(navigator, "clipboard");116+ Object.defineProperty(navigator, "clipboard", {117+ configurable: true,118+ value: { writeText: copy },119+ });120+ const onFill = vi.fn(() => {121+ input.value = "123456";122+ void navigator.clipboard.writeText("123456");123+ });124+125+ try {126+ cleanup = showTOTPSelector(127+ input,128+ [{ id: "1", title: "GitHub", username: "june", hasTotp: true }],129+ onFill,130+ );131+132+ document.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));133+134+ expect(onFill).not.toHaveBeenCalled();135+ expect(input.value).toBe("");136+ expect(copy).not.toHaveBeenCalled();137+ } finally {138+ if (originalClipboard) {139+ Object.defineProperty(navigator, "clipboard", originalClipboard);140+ } else {141+ delete (navigator as { clipboard?: Clipboard }).clipboard;142+ }143+ }144+ });145+146+ it("keeps the click path usable inside the closed TOTP selector", () => {147+ const input = document.createElement("input");148+ document.body.appendChild(input);149+ const originalAttachShadow = Element.prototype.attachShadow;150+ let closedShadow: ShadowRoot | null = null;151+ const attachSpy = vi.spyOn(Element.prototype, "attachShadow").mockImplementation(function (152+ this: Element,153+ init: ShadowRootInit,154+ ) {155+ closedShadow = originalAttachShadow.call(this, init);156+ return closedShadow;157+ });158+ const onFill = vi.fn();159+160+ try {161+ cleanup = showTOTPSelector(162+ input,163+ [{ id: "1", title: "GitHub", username: "june", hasTotp: true }],164+ onFill,165+ );166+167+ (closedShadow as ShadowRoot | null)?.querySelector<HTMLButtonElement>(".sp-fill-btn")?.click();168+169+ expect(onFill).toHaveBeenCalledWith("1");170+ } finally {171+ attachSpy.mockRestore();172+ }173+ });174+175+ it.each(["Escape", "Tab"])("does not dismiss the TOTP selector after an untrusted %s key", (key) => {176+ const input = document.createElement("input");177+ document.body.appendChild(input);178+ const onDismiss = vi.fn();179+ cleanup = showTOTPSelector(180+ input,181+ [{ id: "1", title: "GitHub", username: "june", hasTotp: true }],182+ vi.fn(),183+ { onDismiss },184+ );185+186+ document.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true }));187+188+ expect(onDismiss).not.toHaveBeenCalled();69189 });70190 });src/content/inject.ts+1 −0
@@ -3518,6 +3518,7 @@35183518 }35193519 35203520 function handleKeyDown(e: KeyboardEvent) {3521+ if (!e.isTrusted) return;35213522 if (e.key === "Escape" || e.key === "Tab") {35223523 e.preventDefault();35233524 dismiss(true);