Add an OS clipboard watcher for hidden Unicode - #116
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Introduce `fuckmark clipboard scan|clean|watch` so copied text is checked for Trojan Source, zero-width, and tag smuggling. Emoji ZWJ sequences stay intact. Tests inject a fake clipboard. Co-authored-by: Byte271 <byte271@users.noreply.github.com>
c336e2b to
cf17ba6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c336e2bf0b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
|
|
||
| def _digest(text: str) -> str: | ||
| return hashlib.sha256(text.encode("utf-8")).hexdigest() |
There was a problem hiding this comment.
Hash surrogate-containing snapshots without strict UTF-8
When an injected reader or OS backend returns a string containing a lone surrogate—the default category set explicitly includes surrogate—this strict UTF-8 encoding raises UnicodeEncodeError before the scanner runs. Consequently, watch_clipboard() crashes instead of detecting or cleaning precisely this supported input; hash the Python string with a surrogate-preserving encoding or an encoding-independent representation.
Useful? React with 👍 / 👎.
| ("powershell.exe", "-NoProfile", "-Command", "Get-Clipboard -Raw"), | ||
| ) | ||
| return ( | ||
| ("wl-paste", "--no-newline"), |
There was a problem hiding this comment.
Preserve trailing newlines when reading with wl-paste
On Wayland, the first successful command always uses wl-paste --no-newline, so a legitimate final newline is removed from the clipboard text. A scan therefore examines content different from what was copied, and if any hidden character triggers clean, the rewritten clipboard permanently loses that newline; use the unmodified wl-paste output as the primary read.
Useful? React with 👍 / 👎.
| if on_alert is not None: | ||
| on_alert(alert, snap) | ||
| if clean and alert.removed: | ||
| write(alert.cleaned) |
There was a problem hiding this comment.
Recheck the clipboard before overwriting it
With watch --clean, if the user copies new content after read() but before this write—there is an explicit synchronous on_alert callback in that window—the cleaner overwrites the newer clipboard with a cleaned version of the stale snapshot. Re-read and verify the digest immediately before writing so rapid copy operations cannot lose unrelated clipboard data.
Useful? React with 👍 / 👎.
Hash snapshots with UTF-8 surrogatepass, read Wayland paste without stripping a trailing newline, and re-check the clipboard digest before --clean overwrites a newer copy. Co-authored-by: Byte271 <byte271@users.noreply.github.com>
OS clipboard watcher for the shared
fuckmark-hidden-scan-v1engine (Pillar B item 7).Stack: merge #112 → #113 → #114 → #115 → this. Base is
cursor/scan-language-bindings-cdf8(includes Codex P2 follow-upb76f013).What landed
fuckmark clipboard scan/clean/watchpbpaste,wl-paste,xclip -o,xsel, or PowerShellGet-Clipboard -Rawfuckmark lint(Trojan Source bidi, zero-width, tag smuggling, controls, noncharacters, surrogates)--cleanrewrites the clipboard in place--json,-q,--select,--once,--exit-on-find,--interval,--max-seconds0clean,1findings (including after a successful clean),2usage,3clipboard unavailableevaluate_clipboard_text,watch_clipboard,clean_clipboard_textwith injectable reader/writer/clock for testsdocs/clipboard.md, plus CLI / README / CHANGELOG / install notesCodex P2 follow-up (
5cfa925)surrogatepassso a lone surrogate does not crashwatchwl-pastewithout--no-newline, so a real trailing newline is keptwatch --cleanre-reads and compares digests before writing, so a newer copy is not overwrittenAlgorithm id:
fuckmark-clipboard-watch-v1. Package version stays 0.4.1. Frozen confirmation artifacts are unchanged.