Skip to content

Route every pasteboard write through one primitive - #424

Merged
alexkroman merged 1 commit into
mainfrom
claude/clipboard-one-write-path
Nov 25, 2026
Merged

alexkroman merged 1 commit into
mainfrom
claude/clipboard-one-write-path

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

What & why

SystemClipboard applied its rule for a secret separately in each place that writes the pasteboard. The rule is: keep it off Universal Clipboard, mark it ConcealedType/TransientType, and clear it after concealedLifetime. Each security fix since then found a write path the rule had missed:

  • 3b24d1b added the expiry to write.
  • 54d030c added it to the paste over an unreadable clipboard.
  • 73ae910 added it to restore(_:ifChangeCountIs:) and copied the host-only prepareForNewContents into restore(_:) by hand.

Every write now goes through one private put(_:transient:concealed:expiry:). That covers the paste, the leave-behind, both restores, the text floor and the expiry's own clear. In order, it:

  1. counts the write in ownWrites before it lands,
  2. prepares the pasteboard host-only when concealed (clears it otherwise),
  3. writes .text, .items or .nothing,
  4. adds the markers: after the string for text, and the transient marker on each item for items (a concealed snapshot already carries its concealed marker in its data),
  5. when concealed, schedules expireOurWrite().

It returns false when writeObjects refuses the batch, so the restore still falls through to the plain-string floor (#347). The one concealed write that gets no expiry is a paste whose snapshot its restore will put back. That exception is now an explicit ConcealedExpiry.leftToRestore argument rather than a missing call, and its behaviour is unchanged.

setString is removed; tests call write(_:concealed: false), which was the same call. ARCHITECTURE.md's paste-restore paragraph describes the primitive.

Behaviour change: none in production. A direct caller of restore(_:) (only tests) or an unreachable path could see these differences:

  • restore(_:) now schedules a concealed snapshot's expiry itself, instead of leaving that to restore(_:ifChangeCountIs:), its only production caller. The change count it keys on is the same.
  • A restore that writes nothing (every item empty, no text) no longer bumps the own-write count. That bump never matched a write.
  • If writeObjects refuses a concealed batch and there is no text floor, no expiry is scheduled. The pasteboard is already empty, so the old expiry only cleared an empty pasteboard again.
  • Inside a rebuilt item, the transient marker is now added after the text floor's string instead of before it. Every type is still present.

How it was tested

  • Written in a Linux sandbox with no Swift toolchain: scripts/check.sh --portable passes, as do check-swift-size.sh (SystemClipboard.swift is at 289 lines) and check-test-clock.sh. CI on macOS verifies the build, all tests, swiftlint, swift-format and periphery.

  • New everyConcealedWriteExpires (in SystemClipboardTests+Expiry.swift, an extension of the serialized suite) runs every concealed write path. It checks that each one bumps ownWriteCount, leaves the secret marked ConcealedType and TransientType, and schedules exactly one expiry, which then clears it.

    • The paths covered are the leave-behind, the paste over an unreadable clipboard, restore(_:), restore(_:ifChangeCountIs:), and a restore whose string comes from the text floor.
    • Host-only can't be read back through any public API, so put alone enforces it.
    • restorablePasteSchedulesNothing still pins the restorable concealed paste.
  • scripts/check.sh passes (or CI will, if I'm not on a Mac)

  • I read AGENTS.md and this doesn't reintroduce anything
    deliberately removed

  • Docs updated if behavior changed


Generated by Claude Code

SystemClipboard's rule for a secret — kept off Universal Clipboard,
marked ConcealedType and TransientType, and cleared after
concealedLifetime — was applied at each call site, and each security
fix since found a site it had missed: the expiry was added to write,
then to the unreadable-clipboard paste, then to the restore of a
concealed snapshot, whose host-only scope was also copied in by hand.

Every write (the paste, the leave-behind, both restores, the expiry's
clear) now goes through one private put(_:transient:concealed:expiry:),
which counts the write as Blurt's own, prepares the pasteboard host-only
when concealed, writes the text or items, adds the markers and, when
concealed, schedules the expiry. The one concealed write that is not
expired, a paste whose snapshot its restore will put back, says so with
an explicit .leftToRestore. setString is gone; tests write with
write(_:concealed: false), which was the same call.

Production behaviour is unchanged. Differences only a direct caller of
restore(_:) or an unreachable path can see: restore(_:) now schedules a
concealed snapshot's expiry itself rather than leaving it to
restore(_:ifChangeCountIs:), its only production caller; a restore that
writes nothing no longer bumps the own-write count; a refused batch with
no text floor schedules no expiry over the pasteboard it left empty; and
the transient marker on a rebuilt item now follows its text floor.

A new test pins the invariant: every concealed write path is counted,
marked and given exactly one expiry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 0d78d30 Nov 25, 2026
22 checks passed
@alexkroman
alexkroman deleted the claude/clipboard-one-write-path branch November 25, 2026 21:40
alexkroman pushed a commit that referenced this pull request Nov 25, 2026
No content conflicts: #398 moved AssemblyAIAccount.swift into
BlurtAssemblyAI, and git carried this PR's comment at the early return
along with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
alexkroman pushed a commit that referenced this pull request Nov 25, 2026
One conflict, in DictationSession+Pipeline.swift: #398 renamed the
too-short check's error to the provider-neutral TranscriberError on the
line this PR made log against its own press. Kept both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Vp9Andd7LBEDhGKeC
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