feat: redact cloud credentials on paste - #34
Merged
Merged
Conversation
Copying a block of logs, JSON or ~/.aws/credentials to ask an agent about it carries any live key straight into the model's context. ⌘V now replaces what looks like a cloud credential with [redacted] before the text reaches the session, keeping the surrounding text so the agent still sees what you meant to show it. The rules are regexes in `[paste] redact`, not knowledge in the binary. The part named `secret` is what gets replaced, so the name and quotes around it survive and a mistyped replacement can't eat the context. A broken regex is refused at startup, naming its index, rather than failing silently at paste time. Taken from iTerm2, which puts an ordered transform pipeline behind paste (sanitizePasteEvent: in iTermPasteHelper.m) and ships regex substitution as a tool with no rules of its own. termit ships cloud defaults too, because a tool nobody writes rules for protects nobody. Two things changed on the way: the redacted span is a named capture rather than iTerm2's pattern+substitution pair, and the escape hatch is ⌥⌘V -- iTerm2's Advanced Paste slot -- which avoids the Cmd+Shift combination this codebase already had to work around once. regex was already linked via env_logger, so making it a direct dependency costs 33KB of binary and no compile time. Rust's regex has no backtracking, so a user-supplied pattern cannot hang the terminal. Scope is the user's own paste. ⌘C and OSC 52 are untouched: rewriting a copy would silently break selecting a key on screen in order to use it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 17, 2026
tkc
added a commit
that referenced
this pull request
Sep 25, 2026
* docs: note that a sleeping Mac stops an agent waiting on a reset Claude Code resumes its task by itself when a usage limit resets, but only while its session is alive, which makes leaving termit open the thing that gets work done overnight. A sleeping Mac freezes every process, so the reset passes and nothing happens -- and none of the assertions already on this machine (coreaudiod, sharingd, powerd) hold PreventSystemSleep, so the default state is not enough. `caffeinate -is termit` covers it, and releases both assertions when termit exits. Verified: PreventSystemSleep goes 0 -> 1 while it runs and back to 0 after. The two limits are stated, because both are easy to trip over: -s applies only on AC power, per its man page, and neither flag stops a laptop sleeping when the lid closes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: mask credentials on screen, not on paste The paste-time redaction shipped in #34/#35 solved the wrong problem. The requirement is that a credential still works and simply is not visible, not that it never reaches the program. Redacting the paste turned `export AWS_SECRET_ACCESS_KEY=wJalr...` into `export AWS_SECRET_ACCESS_KEY=[redacted]`, so the shell assigned the literal string and the failure surfaced much later, in an AWS call far from its cause. Masking now happens while drawing. The grid keeps the real text and the pty gets the real bytes, so a pasted export works exactly as typed and ⌘C copies the real value; what disappears is the credential being visible in a screenshot, a screen share, or scrollback an hour later. Redactor::spans returns byte ranges, masked_cells maps them to columns, and the draw loop substitutes a bullet per cell so column alignment -- and any full-screen UI drawn on top of it -- does not shift. The byte-to-column mapping is the part that can silently go wrong, so a test masks a line with double-width characters ahead of the secret and asserts the bullets land on the key and nowhere else. Costs 0.041ms median for a full 47x163 screen with a credential every eighth line, against roughly 1ms to build a frame. An ignored test re-measures it. `[paste]` becomes `[screen]`, since the table now describes what is drawn. ⌥⌘V and Action::PasteRaw are gone: with paste left alone there is nothing to escape from. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copying a block of logs, JSON or
~/.aws/credentialsto ask an agent about it carries any live key straight into the model's context.⌘Vnow redacts before the text reaches the session, keeping the surrounding text so the agent still sees what you meant to show it:The bottom bar says
pasted with 2 secrets redacted — ⌥⌘V pastes it unchanged, so it never happens silently, and⌥⌘Vgives you the real thing when you want it (typing a key intoaws configure).⌘Cand OSC 52 are untouched — rewriting a copy would silently break selecting a key on screen in order to use it.Rules live in config, not in the binary
The part named
secretis what gets replaced, so the name and the quotes around it survive automatically. A broken pattern is refused at startup, naming its index — verified for real:What iTerm2 gave, and what changed
iTerm2 puts an ordered transform pipeline behind paste (
sanitizePasteEvent:iniTermPasteHelper.m: newlines → punctuation → unsafe control codes → tabs → shell escaping → regex substitution → base64) and ships the regex tool with no rules of its own. Two deliberate differences:$1. Marking the span(?P<secret>…)instead means a mistyped replacement can't eat the context.⌥⌘V, not⌘⇧V. That is iTerm2's Advanced Paste slot, and it sidesteps the Cmd+Shift combination this codebase already had to work around once (⌘Iexists because⌘⇧Rdoesn't always arrive).termit ships defaults where iTerm2 ships none, because a tool nobody writes rules for protects nobody — but they stay in config, so no AWS key shape is compiled into termit.
docs/references/paste.mdrecords this.Cost
regexwas already linked viaenv_logger→env_filter, so making it a direct dependency costs 33 KB of binary (9,641,456 → 9,674,560) and no compile time. Rust's regex has no backtracking, so a user-supplied pattern cannot hang the terminal.Limits, stated in the README too
passwordandtokenare deliberately not in the defaults — they fire on code you paste for review and damage it. There is a test asserting ordinary code passes through byte-for-byte.Test
224 pass, 1 ignored. clippy
-D warningsandfmt --checkclean. Nine tests on the redactor cover a real credentials file,aws stsJSON, a GCP service-account key (the\ninside the quoted value is why the quoted rule takes everything to the closing quote), Google API keys and OAuth tokens, code that must survive untouched, empty rules, a rule with nosecretgroup, and a broken pattern. A test pins the README's example to the shipped defaults so the two can't drift.Not covered by a test: the wiring from clipboard through redact to the pty, and whether
⌥⌘Vactually arrives on a given machine — I can't press keys from here.--keytestwill show it; if it doesn't arrive,mask = falseis the fallback.🤖 Generated with Claude Code