Skip to content

feat: widen the paste rules to cover cloud env vars and PEM keys - #35

Merged
tkc merged 1 commit into
mainfrom
redact-cloud-rules
Sep 17, 2026
Merged

tkc merged 1 commit into
mainfrom
redact-cloud-rules

Conversation

@tkc

@tkc tkc commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Follow-up to #34, after reading Claude Code's own credential detector.

What Claude Code actually does

Inspected the shipped binary (~/.local/share/claude/versions/2.1.273). It carries a table of 59 regexes, each {id, source, flags, confidence}, and:

  • No entropy-based detection. entropy appears only in Node internals and in the prose of the maskDuplicates docs. This confirms the limit already stated in our README — a bare AWS secret key is not detectable, and Anthropic reached the same conclusion.
  • Capture group 1 is the part to replace — the same convention as (?P<secret>…) here, and as the sandbox's extract setting.
  • The confidence tier is chosen by the direction the data travels:
scan(e)             → high only   // detect and label, no replacement
redactTokens(e)     → high only
redactContext(e)    → low only
redact(e)           → redactTokens(redactContext(e))   // outbound: both
redactForDisplay(e) → high only   // shown to a person: conservative

Over-redact on the way out; under-redact on the way to a reader. Their value pattern even matches [REDACTED] itself, so re-running is safe.

Worth noting: per the data-usage docs, this detector runs on telemetry, /feedback bundles and transcript uploads only — "Source code, file contents, and other conversation content are uploaded as-is." The path to the model is covered by user-declared rules instead (Read(./.env) deny rules, sandbox mask). termit's paste boundary sits in that gap.

The three rules taken

1. Cloud environment variables — narrowed, not copied. Theirs redacts the value of anything matching AWS_|GOOGLE_|GCP_|GCLOUD_|AZURE_. Free for telemetry; wrong here. It would strip AWS_REGION=us-east-1 and AWS_PROFILE=default out of your paste, and an agent that cannot see your region cannot answer the question you asked. Narrowed to names carrying SECRET, KEY, TOKEN, PASSWORD or CREDENTIAL — there is a test asserting plain cloud settings arrive untouched.

2. PEM private keys, whole. Previously only caught inside a JSON value, so pasting the key file itself went straight through. The -----END …----- marker is required, so prose mentioning -----BEGIN PRIVATE KEY----- is not swallowed to the end of the paste.

3. GOCSPX- client secrets, the A3T access-key prefix, and AWS's base32 alphabet [A-Z2-7].

Deliberately not taken: the low-confidence tier

sensitive-assign fires on password, token, cookie, authorization, session_id, connection_string. That is right for telemetry and wrong for a paste that a person and an agent both read for meaning — it would damage the code you paste for review. termit's paste follows redactForDisplay, not redact.

Also fixed

Redaction is now idempotent and the count honest. A span already reading [redacted] is neither re-counted nor re-replaced, so AWS_ACCESS_KEY_ID=AKIA… — which matches both the prefix rule and the variable-name rule — reports one secret rather than two.

Test

231 pass (up from 224), 1 ignored. clippy -D warnings and fmt --check clean. Seven new tests: cloud env vars redacted, plain cloud settings byte-for-byte unchanged, a PEM block redacted whole with the surrounding sentences kept, an unterminated PEM left alone, GOCSPX-, no count inflation from overlapping rules, and redacting twice being a no-op. The README's rule list is regenerated from the shipped defaults and pinned to them by the existing test.

docs/references/paste.md records the investigation.

🤖 Generated with Claude Code

Read Claude Code's own detector to see what it catches. It ships a table
of 59 regexes tagged high or low confidence, picks a tier by the
direction the data is travelling -- both tiers outbound to telemetry,
high only for anything shown to a person -- and has no entropy-based
detection at all, which confirms the limit already written down here.
Three of its rules were missing on our side:

- Cloud environment variables. NOT copied as-is: their rule redacts the
  value of anything matching AWS_|GOOGLE_|AZURE_, which is free for
  telemetry but would strip AWS_REGION=us-east-1 and AWS_PROFILE=default
  out of a paste, and an agent that cannot see your region cannot answer
  the question. Narrowed to names carrying SECRET, KEY, TOKEN, PASSWORD
  or CREDENTIAL.
- PEM private keys, as a whole block. Previously only caught inside a
  JSON value, so pasting the file itself went through. The END marker is
  required so prose mentioning -----BEGIN PRIVATE KEY----- survives.
- GOCSPX- client secrets, the A3T access-key prefix, and AWS's base32
  alphabet.

Their low-confidence tier is deliberately left out: sensitive-assign
fires on password, token, cookie and authorization, which would damage
the code you paste for review. termit's paste is read for meaning by a
person and an agent, so it follows redactForDisplay, not redact.

Redaction is now idempotent and the count honest: a value already
reading [redacted] is neither re-counted nor re-replaced, so overlapping
rules on AWS_ACCESS_KEY_ID=AKIA... report one secret, not two.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tkc
tkc merged commit 11c7162 into main Sep 17, 2026
1 check passed
@tkc
tkc deleted the redact-cloud-rules branch September 17, 2026 03:16
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>
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.

1 participant