Skip to content

Restore the text floor when a clipboard snapshot kept only empty marker types - #354

Merged
alexkroman merged 2 commits into
fix/secure-flag-unresolved-readfrom
fix/clipboard-marker-only-restore
Nov 24, 2026
Merged

alexkroman merged 2 commits into
fix/secure-flag-unresolved-readfrom
fix/clipboard-marker-only-restore

Conversation

@alexkroman

@alexkroman alexkroman commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #347. Stacked on fix/secure-flag-unresolved-read. That branch has no PR yet and holds the #348 commit, which adds SystemClipboard.concealedType. Retarget this PR to main once that branch lands.

The bug

A password manager's copy whose string was promised (and declined) snapshots as an item that holds only the empty org.nspasteboard.ConcealedType marker. Empty Data() isn't nil, so the snapshot kept it. restore wrote that marker-only item back, writeObjects returned true, and the early return skipped the plainText floor. After a successful dictation paste, the user's copied password was gone.

The fix (SystemClipboard.restore)

  • A new helper, restorableItems, restores an item only if it carries non-empty data. An item with only markers is not contents.
  • When no item kept a .string of its own, plainText goes into the first item instead of being written separately afterwards. The text then keeps that item's markers, so a concealed password comes back concealed rather than as a plain string a clipboard manager would archive.
  • A restore that includes ConcealedType is written with .currentHostOnly, the same way Blurt's own concealed writes are kept off Universal Clipboard.

Tests

New cases in SystemClipboardTests:

  • marker-only snapshot + plainText → the string comes back, still Concealed + Transient. Fails on the old code.
  • marker-only snapshot, no plainText → the transcript is left in place, not replaced by bare markers. Fails on the old code.
  • RTF payload whose string was lost → the text floor is folded back in. Passes either way, because NSPasteboard derives a string from RTF, so it's coverage only.
  • a real string + ConcealedType copy, run through writeAndPrepareRestore from start to finish.

swift test --filter SystemClipboard: 18/18 pass.

scripts/check.sh failures, none from this diff:

Review follow-up (81dcb35)

  • The 90 s clear survives a restore. A restore is a write, so it cancelled the clear pending on a concealed clipboard, whether Blurt's own leftover or a password manager's timer, and the password then stayed on the clipboard indefinitely. A concealed restore now schedules its own clear. New test: restoredConcealedClipboardExpires.
  • The fallback path keeps concealment. If writeObjects refuses the batch, the plain-text fallback now goes through setString(…, concealed:), so it gets the concealed marker, this-Mac-only scope and the 90 s clear. It no longer writes a plain string.
  • Doc fix. PasteboardSnapshot.plainText's comment now matches restorableItems.
  • Tests moved. The concealed tests now live in SystemClipboardConcealedTests.swift, as an extension of the same .serialized suite (so they still never race on NSPasteboard.general). This keeps both files under SwiftLint's file and type-body length limits.

🤖 Generated with Claude Code

alexkroman-assembly and others added 2 commits November 24, 2026 11:55
A password manager's copy whose string was promised snapshots as an item
holding nothing but the empty org.nspasteboard.ConcealedType marker.
restore wrote that item back, writeObjects reported success, and the
plainText floor never ran — so a successful dictation paste replaced the
user's copied password with a bare marker.

restore now counts an item only when it carries non-empty data, and folds
plainText into the first item when no item kept a string of its own, so
the text comes back with that item's markers (a concealed password stays
concealed). A concealed restore is written current-host-only, matching
how Blurt's own concealed writes stay off Universal Clipboard.

Fixes #347

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts lifetime

The restore is itself a write, so it voided the 90 s clear pending on a
concealed clipboard — Blurt's own leave-behind, or a password manager's
timer — and the restored secret then stayed on the clipboard
indefinitely. A concealed restore now schedules its own clear.

The text-floor fallback (a refused writeObjects) wrote a plain string,
dropping ConcealedType and .currentHostOnly. It now goes through
setString with the snapshot's concealed flag, so it gets the same
markers, host scope and expiry.

Also corrects PasteboardSnapshot.plainText's doc to match
restorableItems, and moves the concealed tests into an extension of
SystemClipboardTests (same serialized suite) to stay under the file and
type-body length limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman merged commit ac7d414 into fix/secure-flag-unresolved-read Nov 24, 2026
1 check passed
@alexkroman
alexkroman deleted the fix/clipboard-marker-only-restore branch November 24, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants