diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d1f0073..45ec051c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,18 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li (`package.json`, `server/package.json`, `ui/package.json`, `server/src/version.ts`) and is tagged `vX.Y.Z`. +## Unreleased + +### Fixed + +- **The clipboard widget masks one-time codes.** A six-digit code copied from a text message or + an authenticator (`482913`, `482 913`, `4829-1375`) showed in full on the Edge and on a paired + iPad; any run of four to eight digits copied on its own is now shown as a secret, and still + copies back with a tap. Numbers inside a sentence and phone numbers are shown as before. +- **The clipboard widget leaves alone what more password managers copy.** Besides the standard + "concealed" and "transient" markers, a copy from 1Password, KeeWeb, Butler, Typeit4me or a + Keyboard Maestro generator is no longer recorded at all. + ## 0.5.0 — 2026-10-19 ### Added diff --git a/server/src/providers/clipboard.ts b/server/src/providers/clipboard.ts index 40dc5472..40d8db12 100644 --- a/server/src/providers/clipboard.ts +++ b/server/src/providers/clipboard.ts @@ -32,6 +32,20 @@ export const SECRET_MIN_LENGTH = 32 */ export const SECRET_TOKEN_MIN_LENGTH = 8 +/** + * A one-time code copied on its own: four to eight digits, or two groups of three or four split by + * one space or dash (`482913`, `482 913`, `4829-1375`), and nothing else in the text. + * + * Every other rule starts at eight characters, so a six-digit code from an SMS or an + * authenticator went up on the Edge in full, stayed in the history and reached a paired iPad. + * + * The trade-off: a bare number of that size copied alone — a year, a postcode, an extension — is + * masked too, and stays copyable. Anything around the digits (`Meeting at 2026`), a phone number + * (more digits, more groups) and a lopsided split (`4 82913`) are left alone: masking every number + * in a clipboard would hide much more than it protects. + */ +const ONE_TIME_CODE = /^(\d{4,8}|\d{3,4}[ -]\d{3,4})$/ + /** Substrings that mark a text as a secret whatever its shape. Matched case-insensitively. */ const SECRET_MARKERS = ['password', 'mot de passe', 'secret', 'bearer', 'private key', 'sk-', 'ghp_', 'github_pat_', 'xoxb-', 'api key', 'apikey'] @@ -42,12 +56,19 @@ const SECRET_MARKERS = ['password', 'mot de passe', 'secret', 'bearer', 'private * value the same way. `pbpaste` reports neither — it hands over the text and says nothing — so * the types have to be read separately. Honoured by not recording the entry at all. * - * https://github.com/sindresorhus/Pasteboard-Viewer documents the convention. + * https://github.com/sindresorhus/Pasteboard-Viewer documents the convention. The last group are + * the private markers some applications set instead of (or as well as) it — 1Password, KeeWeb, + * Butler, Typeit4me, Keyboard Maestro — which other clipboard managers honour too. */ export const PRIVATE_PASTEBOARD_TYPES = [ 'org.nspasteboard.ConcealedType', 'org.nspasteboard.TransientType', 'org.nspasteboard.AutoGeneratedType', + 'com.agilebits.onepassword', + 'net.antelle.keeweb', + 'de.petermaurer.TransientPasteboardType', + 'com.typeit4me.clipping', + 'Pasteboard generator type', ] /** @@ -142,9 +163,10 @@ export function capText(text: string): string { /** * Whether a text is treated as a secret. * - * Three ways in: it names one outright, it is a long unbroken run (an API key), or it is a - * shorter unbroken run mixing character classes — which is what an ordinary password looks like, - * and what the length rule alone used to publish in full onto a screen on a desk. + * Four ways in: it names one outright, it is a one-time code (`ONE_TIME_CODE`), it is a long + * unbroken run (an API key), or it is a shorter unbroken run mixing character classes — which is + * what an ordinary password looks like, and what the length rule alone used to publish in full + * onto a screen on a desk. * * Deliberately generous: a false positive costs the user a preview they can still copy, a false * negative puts their password on the wall. Anything with whitespace in it is prose and is left @@ -154,6 +176,8 @@ export function isSecret(text: string): boolean { const trimmed = text.trim() const lower = trimmed.toLowerCase() if (SECRET_MARKERS.some((marker) => lower.includes(marker))) return true + // Before the whitespace rule: `482 913` is a code, not prose. + if (ONE_TIME_CODE.test(trimmed)) return true if (/\s/.test(trimmed)) return false if (trimmed.length >= SECRET_MIN_LENGTH) return true if (trimmed.length < SECRET_TOKEN_MIN_LENGTH) return false diff --git a/server/test/clipboard.test.ts b/server/test/clipboard.test.ts index 8dabb874..d6e29afa 100644 --- a/server/test/clipboard.test.ts +++ b/server/test/clipboard.test.ts @@ -64,6 +64,13 @@ describe('clipboard history', () => { const snap = await p.poll!() as ClipboardSnapshot expect(snap.entries).toHaveLength(1) }) + it('records a one-time code masked, never in full', async () => { + const { pasteboard } = fake('482913') + const p = createClipboardProvider(pasteboard, now) + const snap = await p.poll!() as ClipboardSnapshot + expect(snap.entries.map((e) => [e.preview, e.masked])).toEqual([[MASKED_PREVIEW, true]]) + expect(JSON.stringify(snap)).not.toContain('482913') + }) it('moves an entry copied again back to the front instead of duplicating it', async () => { const { pasteboard, set } = fake('one') const p = createClipboardProvider(pasteboard, now) @@ -211,6 +218,19 @@ describe('what counts as a secret', () => { it('still masks a destination long enough to be carrying a token', () => { expect(isSecret('https://example.com/reset?token=' + 'a'.repeat(40))).toBe(true) }) + it('masks a one-time code: a short run of digits copied on its own', () => { + // Eight characters was the floor of every other rule, so a six-digit code went up on the + // Edge in full, stayed in the history and reached a paired iPad. + for (const text of ['482913', '4829', '48291375', '482 913', '482-913', '4829-1375', ' 482913\n']) { + expect(isSecret(text), text).toBe(true) + } + }) + it('leaves numbers in prose, and longer or oddly split numbers, alone', () => { + for (const text of ['Meeting at 2026', 'Room 4829 at 10:30', '123', '482913750', + '06 12 34 56 78', '+33 6 12 34 56 78', '4 82913', '48 2913']) { + expect(isSecret(text), text).toBe(false) + } + }) it('counts the character classes a text draws on', () => { expect(characterClasses('abcdef')).toBe(1) expect(characterClasses('abcDEF')).toBe(2) @@ -229,7 +249,8 @@ describe('a pasteboard that asks not to be remembered', () => { it('records nothing at all for a concealed pasteboard', async () => { for (const type of ['org.nspasteboard.ConcealedType', 'org.nspasteboard.TransientType', - 'org.nspasteboard.AutoGeneratedType']) { + 'org.nspasteboard.AutoGeneratedType', 'com.agilebits.onepassword', 'net.antelle.keeweb', + 'de.petermaurer.TransientPasteboardType', 'com.typeit4me.clipping', 'Pasteboard generator type']) { const p = createClipboardProvider(board('the password itself', ['public.utf8-plain-text', type])) const snapshot = await p.poll!() as { entries: unknown[] } // Not masked — absent. A password manager's copy is not ours to hold.