Repository navigation
feat: unified gitleaks sanitizer + wire redaction across all upload paths; dedup shared helpers - #91
Conversation
Extract the duplicated `read + JSON.parse + swallow` readers, the atomic
JSON writer, stdin reading, and git-root discovery into a new leaf module
(lib/io.js, Node built-ins only, so any module can import it without cycles),
and collapse the two divergent JWT-expiry checks into one parametrized helper.
- lib/io.js: safeReadJson / atomicWriteJson / readStdinJson / findGitRoot
- credstore, settings, paths, repo-scope, user_prompt_expansion_signin delegate
- settings.saveTelemetryOptIn now writes atomically (0o600)
- jwt.isJwtExpired(token, {skewSeconds, treatMissingAsExpired}); credstore's
isLicenseTokenExpired delegates (semantics preserved: missing token -> expired,
5-min skew)
- test/lib.test.js locks io + expiry behavior
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KoEUHYQTz1Tx61FcteE979
The activate/refresh/exchange calls shared an identical fetch skeleton
(Bearer header + JSON body + AbortSignal timeout) with three copies that had
drifted only in timeout and status handling. Extract the skeleton into
lib/http.js#postBearerJson; each caller keeps its own status-code branching
and body parsing (return-null-with-log vs throw), which genuinely differ.
- lib/http.js: postBearerJson(url, bearer, body, {timeoutMs})
- license-activation refreshExpiredJwt / trySilentGhActivate and signin
exchangeForLicense delegate the fetch; per-status behavior unchanged
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KoEUHYQTz1Tx61FcteE979
… all upload paths Previously secret/PII redaction ran in exactly one place (the SessionStart harness block), so transcripts, prompts, assistant messages, and tool outputs shipped raw. A scan of a real transcript found the OS username ($HOME path) in ~80% of lines plus emails and tokens in the clear. This unifies detection and routes every upload path through one boundary. - lib/rules.js: single gitleaks-derived rule table (MIT, see NOTICE) with keyword pre-filter, Shannon-entropy gate, and stopword allowlist; replaces the two hand-rolled Tier-1/Tier-2 detector arrays - lib/sanitize.js: one redactString loop; scrubDeep walks values AND keys, HMAC- hashes path-bearing keys (incl. nested) and the $HOME/username prefix; containsTier1 -> containsSecret; POLICY_VERSION 2.0.0 - logger.js: central sanitizeEventData catch-all over every hook payload, with a per-event _sanitization tally; fixed fields win key collisions - transcript pipeline (sanitizeLine) now scrubs the whole line, not just cwd - tool hooks return raw fields; central boundary hashes paths + redacts content (command is scrubbed for content so its shape is preserved, not wholesale-hashed) - fix: anchor the auth key-pattern so author/authored_by aren't over-redacted - regex spans bounded + home-dir hash memoized to keep the hot path cheap - README/plugin.json privacy claims updated; bump to 0.21.0 - test/sanitize.test.js added; harness meta rename Verified: node --test 49/49; real 20k-line transcript scrub leaves 0 $HOME/ email/token hits with valid JSON; plugin validate passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoEUHYQTz1Tx61FcteE979
WalkthroughThis PR replaces tiered secret detection with a curated rule-table redaction engine (Gitleaks-derived), centralizes sanitization at the hook boundary via ChangesSecret/PII sanitization rewrite and centralization
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
skillmeter/scripts/lib/http.js (1)
21-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a default for the
optsparam.Destructuring
{ timeoutMs }with no default will throw a rawTypeErrorif a future caller omits the options object, rather than a clear error about a missing timeout.♻️ Proposed defensive default
-function postBearerJson(url, bearer, body, { timeoutMs }) { +function postBearerJson(url, bearer, body, { timeoutMs } = {}) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@skillmeter/scripts/lib/http.js` around lines 21 - 31, The postBearerJson helper currently destructures { timeoutMs } without a default, so callers that omit the options object will throw a raw TypeError. Update postBearerJson to give the options parameter a default empty object, and keep using timeoutMs inside the fetch/AbortSignal.timeout flow so missing opts fails gracefully instead of during destructuring.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@skillmeter/README.md`:
- Around line 228-229: The privacy docs in README are out of sync with the
sanitizer behavior: `command` is not wholesale HMAC-hashed and `repo_root` /
`repo_remote_org` should not be grouped with path-bearing fields. Update the
documentation around the sanitizer description to match the actual handling
implemented for `command` and the repo metadata fields, using the existing
privacy/sanitization section as the place to correct the wording.
---
Nitpick comments:
In `@skillmeter/scripts/lib/http.js`:
- Around line 21-31: The postBearerJson helper currently destructures {
timeoutMs } without a default, so callers that omit the options object will
throw a raw TypeError. Update postBearerJson to give the options parameter a
default empty object, and keep using timeoutMs inside the
fetch/AbortSignal.timeout flow so missing opts fails gracefully instead of
during destructuring.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 84c550af-10d9-43d2-8026-f7706ea49ea6
📒 Files selected for processing (27)
skillmeter/.claude-plugin/plugin.jsonskillmeter/NOTICEskillmeter/README.mdskillmeter/scripts/credstore.jsskillmeter/scripts/harness.jsskillmeter/scripts/lib/http.jsskillmeter/scripts/lib/io.jsskillmeter/scripts/lib/jwt.jsskillmeter/scripts/lib/license-activation.jsskillmeter/scripts/lib/paths.jsskillmeter/scripts/lib/repo-scope.jsskillmeter/scripts/lib/rules.jsskillmeter/scripts/lib/sanitize.jsskillmeter/scripts/lib/settings.jsskillmeter/scripts/lib/transfer.jsskillmeter/scripts/logger.jsskillmeter/scripts/permission_denied.jsskillmeter/scripts/permission_request.jsskillmeter/scripts/post_tool_use.jsskillmeter/scripts/post_tool_use_failure.jsskillmeter/scripts/pre_tool_use.jsskillmeter/scripts/session_start.jsskillmeter/scripts/signin.jsskillmeter/scripts/user_prompt_expansion_signin.jsskillmeter/test/harness.test.jsskillmeter/test/lib.test.jsskillmeter/test/sanitize.test.js
| - **Path-bearing tool fields** (`file_path`, `path`, `command`, …) and the | ||
| `cwd` / `repo_root` / `repo_remote_org` fields are HMAC-hashed wholesale. |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Align the privacy docs with the sanitizer behavior: command is scrubbed as content, not wholesale-hashed, and repo_root / repo_remote_org shouldn’t be listed with the path-bearing fields.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@skillmeter/README.md` around lines 228 - 229, The privacy docs in README are
out of sync with the sanitizer behavior: `command` is not wholesale HMAC-hashed
and `repo_root` / `repo_remote_org` should not be grouped with path-bearing
fields. Update the documentation around the sanitizer description to match the
actual handling implemented for `command` and the repo metadata fields, using
the existing privacy/sanitization section as the place to correct the wording.
What & why
Previously secret/PII redaction ran in exactly one place (the SessionStart harness block), so transcripts, prompts, assistant messages, and tool outputs shipped raw. A scan of a real 20k-line transcript found the OS username (
$HOMEpath) in ~80% of lines, plus emails and tokens in the clear — whileplugin.jsonclaimed "secrets redacted, paths hashed". This PR unifies detection on a gitleaks-derived rule table and routes every upload path through one sanitization boundary, then consolidates the duplicated helper code the audit surfaced.Commits (3, each independently green)
1.
refactor: consolidate file I/O + JWT-expiry helpers into lib/io.jslib/io.js(safeReadJson,atomicWriteJson,readStdinJson,findGitRoot) — Node built-ins only, no import cycles.read+JSON.parse+swallowcopies, the atomic writer, stdin reading, and git-root discovery now delegate to it.settings.saveTelemetryOptInwrites atomically; two divergent JWT-expiry checks collapse into one parametrizedjwt.isJwtExpired(token, {skewSeconds, treatMissingAsExpired})(semantics preserved).2.
refactor: consolidate Bearer-token POST into lib/http.jshttp.postBearerJson; each caller keeps its own status-code branching and timeout.3.
feat: unify secret/PII sanitizer on gitleaks rules and wire it across all upload pathslib/rules.js: single gitleaks-derived rule table (MIT — seeNOTICE) with keyword pre-filter, Shannon-entropy gate, stopword allowlist; replaces the two hand-rolled Tier-1/Tier-2 arrays.lib/sanitize.js: oneredactStringloop;scrubDeepwalks values and keys, HMAC-hashes path-bearing keys (incl. nested) and the$HOME/username prefix;containsTier1→containsSecret;POLICY_VERSION2.0.0.logger.js: centralsanitizeEventDatacatch-all over every hook payload + per-event_sanitizationtally; fixed fields win key collisions.sanitizeLine) scrubs the whole line, not justcwd. Tool hooks return raw fields; the central boundary hashes paths + redacts content (commandis content-scrubbed so its shape is preserved).authkey-pattern soauthor/authored_byaren't over-redacted. Bounded regex spans + memoized home-dir hash for hot-path cost. README/plugin.json privacy claims updated; bump to 0.21.0.Verification
node --test→ 49/49 pass (newtest/sanitize.test.js,test/lib.test.js).$HOME/ email / token hits, all lines valid JSON, ~1.4s (off the hot path).[REDACTED_SECRET], email→[EMAIL], nestedfile_path→HMAC, command shape preserved.claude plugin validate skillmeter✔. Each of the 3 commits loads independently.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation