Skip to content

Exclude Strongbox's clipboard writes from Windows Clipboard History / cloud sync - #32

Merged
jpol34 merged 2 commits into
mainfrom
feat/clipboard-history-exclusion
Sep 16, 2026
Merged

jpol34 merged 2 commits into
mainfrom
feat/clipboard-history-exclusion

Conversation

@jpol34

@jpol34 jpol34 commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Real-value clipboard writes on Windows (reveal's copy) now go through a P/Invoke Win32 clipboard write (OpenClipboard/EmptyClipboard/SetClipboardData) that also registers CanIncludeInClipboardHistory/CanUploadToCloudClipboard as 0 (excluded) — Microsoft's documented format names for legacy apps to opt out of Clipboard History and cloud clipboard sync
  • Clearing to an empty string stays on plain Set-Clipboard (nothing to protect there), so the auto-clear ThreadJob doesn't need the P/Invoke type re-declared in its init script
  • README documents the hardening and its limit (only covers Strongbox's own writes; can't retroactively scrub a value some other app already copied)

Test plan

  • Invoke-Pester -Path Tests/Strongbox.Tests.ps1 — 43 passed, 1 pre-existing skip
  • Invoke-Pester -Path Tests/Strongbox.Cli.Tests.ps1 — 18/18 passed
  • Manual: strongbox reveal tools.StrongboxSelfTest then Get-Clipboard -Raw round-trips the correct value via the new P/Invoke path
  • Still needed, can't be scripted: visually confirm in Win+V (Clipboard History) that the revealed value does not appear there. Attempted a scripted check via the WinRT Clipboard.IsHistoryEnabled()/history API first — that type failed to load from this pwsh process (Unable to find type [...ContentType=WindowsRuntime]), which is exactly the WinRT-from-unpackaged-process reliability gap the plan flagged as the reason to use P/Invoke instead of SetContentWithOptions as primary. No way to verify the history-exclusion outcome itself without a human checking Win+V.

Closes #29.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbfuHLCmCUaTFi6A1gKugh

jpol34 and others added 2 commits September 16, 2026 18:01
…loud sync

reveal's copy-to-clipboard (and any other real-value clipboard write)
now goes through a P/Invoke Win32 clipboard write that additionally
sets the two clipboard formats Windows documents for opting a write
out of Clipboard History (Win+V) and cloud clipboard sync -
Set-Clipboard has no way to set those. Clearing to an empty string
(the auto-clear job, and set --from-clipboard's post-ingest clear)
stays on plain Set-Clipboard, since there's nothing to protect there.

Closes #29.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RbfuHLCmCUaTFi6A1gKugh
…up cost

- Check GlobalAlloc/GlobalLock/SetClipboardData return values instead
  of discarding them - a null pointer previously would have reached
  Marshal.Copy and crashed the process uncatchably
- Free any GlobalAlloc'd block whose SetClipboardData call never
  succeeded, instead of leaking it (ownership only transfers on
  success)
- Retry OpenClipboard a few times before giving up, matching
  Set-Clipboard's own tolerance for transient clipboard contention
- Move the Add-Type compile behind a lazy Install-StrongboxWin32ClipboardType
  call, invoked only by the two code paths that actually write a real
  value, instead of unconditionally on every Windows invocation
- Treat a failed history-exclusion flag write as a warning, not a
  failure of the whole clipboard write (the real value already
  succeeded by that point)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RbfuHLCmCUaTFi6A1gKugh
@jpol34
jpol34 merged commit 569ef4a into main Sep 16, 2026
1 check passed
@jpol34
jpol34 deleted the feat/clipboard-history-exclusion branch September 16, 2026 23:06
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.

Exclude Strongbox's clipboard writes from Windows Clipboard History / cloud sync

1 participant