feat(security): add redact secretScan mode with placeholder-aware copy - #191
Conversation
`secretScan = "redact"` replaces an ordinary API token in structured config (.claude.json, mcp.json, Codex config.toml, hook settings) with a $AGENTSYNC_REDACTED_<FIELD> placeholder and pushes, instead of aborting. A secret in prose still aborts; the catastrophic tier (age key, PEM) still blocks in every mode. On copy, mergePreservingSecrets (new src/core/secret-merge.ts) merges incoming over the local file so a placeholder never overwrites a real local value, local-only entries survive, and array elements (e.g. MCP args) merge element-wise. Wired into all four redacting adapters: claude, codex, cursor, vscode. The cursor/vscode apply paths previously overwrote wholesale. TUI Config tab: redact joins the cycle, a "what this means" panel explains the selected mode, and switching to off prompts a y/n confirm (blocking modal). Closes #181. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011L7s33UCjpQkreXW7amAw2
|
Warning Review limit reached
More reviews will be available in 48 minutes and 26 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangessecretScan redact mode end-to-end
Sequence Diagram(s)sequenceDiagram
participant User
participant performPush
participant sanitizer as redactSecretLiterals
participant Vault
User->>performPush: push with secretScan=redact
performPush->>sanitizer: scan structured config fields
alt ordinary API token detected
sanitizer-->>performPush: replace with $AGENTSYNC_REDACTED_FIELD (non-fatal)
performPush->>Vault: write config with placeholder (no real secret)
else catastrophic secret (age key / PEM)
sanitizer-->>performPush: leave intact, no redaction warning
performPush->>sanitizer: scanForSecrets on output
sanitizer-->>performPush: Detected literal secret → fatal abort
else secret in prose/markdown body
sanitizer-->>performPush: Detected literal secret → fatal abort
end
sequenceDiagram
participant Vault
participant applyAgent as applyXxxMcp / applyCodexConfig
participant mergePreservingSecrets
participant LocalFS as Local config file
Vault->>applyAgent: restored incoming config (may contain $AGENTSYNC_REDACTED_* placeholders)
applyAgent->>LocalFS: read existing file
alt file absent
applyAgent->>LocalFS: write restored content directly
else file present
applyAgent->>mergePreservingSecrets: merge(existing, incoming)
note over mergePreservingSecrets: placeholder never overwrites real local value
mergePreservingSecrets-->>applyAgent: merged result + placeholder paths
applyAgent->>LocalFS: write merged result
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/agents/_utils.ts`:
- Around line 112-127: The functions `getJsoncObjectAtKey` and
`parseJsoncObject` are both discarding parser errors by passing an empty array
to parse(). To fix this, create an errors array variable instead of passing an
empty array, pass this errors variable to the parse function to capture any
parsing errors, and then check if the errors array is non-empty after parsing —
if errors exist, return undefined instead of the parsed result to prevent
malformed JSONC from being treated as valid mergeable data. Apply this fix to
both functions where parse() is called.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 7859824f-a9bf-45dc-8598-441632732a9f
📒 Files selected for processing (23)
CLAUDE.mddocs/architecture.mddocs/commands.mddocs/operations.mdsrc/agents/_utils.tssrc/agents/claude/__tests__/index.test.tssrc/agents/claude/index.tssrc/agents/codex/__tests__/index.test.tssrc/agents/codex/index.tssrc/agents/cursor/__tests__/index.test.tssrc/agents/cursor/index.tssrc/agents/vscode/__tests__/index.test.tssrc/agents/vscode/index.tssrc/commands/__tests__/push.test.tssrc/commands/tui/__tests__/config-tab.test.tssrc/commands/tui/app.tssrc/commands/tui/state.tssrc/commands/tui/tabs/config.tssrc/config/schema.tssrc/core/__tests__/sanitizer.test.tssrc/core/__tests__/secret-merge.test.tssrc/core/sanitizer.tssrc/core/secret-merge.ts
Address CodeRabbit review on PR #191: getJsoncTopLevelKey and parseJsoncObject passed an empty errors array to jsonc-parser, which is fault-tolerant and returns a partially-recovered object on malformed input. A corrupt local config could then become a bad merge base on copy. Now check errors.length === 0 (matching setJsoncTopLevelKey) and return undefined on any parse error, so a malformed local file is treated as "no value". Adds regression tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011L7s33UCjpQkreXW7amAw2
Summary
Completes #181: adds a
secretScan = "redact"mode so a literal API token in a structured config (.claude.json,mcp.json, Codexconfig.toml, hook settings) is replaced with a$AGENTSYNC_REDACTED_<FIELD>placeholder and pushed, instead of aborting the whole push. Pairs it with a placeholder-awarecopyso the round trip is safe, and surfaces it in the TUI.Builds on #190 (the catastrophic always-block tier), which still applies in every mode —
redactandoffincluded.How it works (the round trip)
redactmode):redactSecretLiteralsreplaces an ordinary token with$AGENTSYNC_REDACTED_<FIELD>and emits a non-fatalRedacted literal secretnotice (vs the fatalDetected literal secret). A catastrophic value (age key, PEM) is left untouched so the centralscanForSecretsstill blocks it. A secret in prose (markdown) has no field to replace, so it still aborts.mergePreservingSecrets, newsrc/core/secret-merge.ts): merges incoming over the local file — an incoming placeholder never overwrites a real local value, local-only entries survive, and array elements (e.g. a token in MCPargs) merge element-wise. Wired into all four adapters that redact structured config: claude, codex, cursor, vscode.redactjoins the←/→cycle, a "What this means" panel explains the selected mode, and switching tooffprompts ay/nconfirm (it pushes live secrets). The confirm is a blocking modal so a globalpcan't push behind it.Notes from the senior-review gate
The pre-commit review caught and this PR fixes:
copyfor cursor and vscode wholesale-overwrote the local MCP file — a placeholder would clobber a working local key. Now merged like claude/codex.args); now element-wise.applyClaudeMcp/cursor/vscode placeholder-preservation, and explainer tests.Tests
1003 pass / 0 fail. New coverage: redact-mode redactor,
mergePreservingSecrets(incl. arrays +__proto__), placeholder preservation across claude/codex/cursor/vscode apply, TUI confirm/cancel/redact-applies + explainer, redact prose-abort e2e.Closes #181.
🤖 Generated with Claude Code
https://claude.ai/code/session_011L7s33UCjpQkreXW7amAw2
Summary by CodeRabbit
New Features
Improvements
Documentation