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
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