Skip to content

fix: check every enclosing server and endpoint before reusing a local secret - #13

Merged
Fafoooo merged 2 commits into
mainfrom
fix/secret-scope-ancestors
Oct 10, 2026
Merged

Fafoooo merged 2 commits into
mainfrom
fix/secret-scope-ancestors

Conversation

@Fafoooo

@Fafoooo Fafoooo commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Why

An automated commit security review found two problems in the secret-reuse scope rule that shipped in 1.1.0. When the repo has {{REDACTED}}, a real local secret is reused only if its scope is unchanged. Both problems need a malicious or compromised backup repo to exploit.

  1. Scope confusion. The nearest entry won. A nested object under a key that happens to be in ENTRY_PARENTS (servers, mcp, …) reset the enclosing server's decision. A changed outer command could therefore still receive the token.
  2. Control regression. Before the scope rule, command/args/url were checked on any object. The scope rule recognised servers only by their parent key. A server under an unrecognised map, such as context_servers, was compared only at its env block.

Fix

The first commit on this branch ANDed the checks and added a list of endpoint keys. A follow-up scan then pointed out that any such key list is incomplete by nature: host, uri, proxy and others would be missing. So the second commit removes every key list from the safety decision:

  • Anchored scopes. A marker leaf's scope is its entry under one of a few maps anchored at the document root: mcpServers, mcp_servers, servers, mcp, mcp.servers, model_providers and profiles. The longest anchored map wins. Outside those maps the scope is the leaf's whole top-level subtree, and a leaf at the top level is scoped to the whole document. mcp.ts passes rootIsEntry, so a bare server definition is its own scope.
  • Reuse condition. A local secret is reused only when its scope is blindEqual between repo and local. Repo marker paths are dropped from both sides and key order is ignored. Any added, removed or changed key blocks reuse.
  • Safety never depends on the map list. A map arbella does not know falls back to the coarser top-level subtree, so an omission can only make the rule stricter.
  • Threat model. Written into a code comment and the README: the backup repo stays trusted, because it ships hooks and MCP commands that run code. This guard keeps a secret from silently following a changed endpoint or block. It is not a sandbox against a malicious repo.

Unsafe values are still kept locally and reported, never moved or destroyed.

Test plan

  • npm run typecheck && npm test: 892 tests (875 on main).
  • New cases, including an unknown endpoint key (host) under an unrecognised map, the coarse fallback (a sibling entry changed), the VS Code mcp.servers shape, codex profiles, a top-level apiKey, and scopeOf unit cases. Earlier cases:
    • a nested servers map cannot reset the entry;
    • an unrecognised server map with a changed command is unsafe;
    • a changed base_url outside any known entry is unsafe;
    • an unchanged context_servers entry still reuses its value;
    • a settings env whose only difference is the marker still reuses its value;
    • a missing local object at a required level means no reuse.
  • One existing test asserted the leak (a bare server root with a changed cwd) and was corrected.

https://claude.ai/code/session_01FeijYwkkKBqRx4GkS1BRGr

… secret

A nested object under a key like "servers" no longer resets the enclosing
entry's scope check, and objects carrying command/url/base_url-style hints
are compared wherever they sit, not only under known entry keys. The checks
are ANDed down the tree; a marker leaf reuses its local value only if its
parent, every enclosing entry and every enclosing hinted object are unchanged.

Claude-Session: https://claude.ai/code/session_01FeijYwkkKBqRx4GkS1BRGr
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5273d997-a4c6-46b9-bdfd-c0e4b0a60ec0

📥 Commits

Reviewing files that changed from the base of the PR and between 560fd96 and 06d578c.


📒 Files selected for processing (3)
  • README.md
  • src/core/placement/redacted.ts
  • test/unit/redacted-values.test.ts

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

A real local secret was reused only if key lists (endpoint hints, entry
parent names at any depth) said its block was unchanged, which is
incomplete by nature. The scope is now derived from the leaf's absolute
path: its entry under an anchored map (mcpServers, mcp.servers,
model_providers, profiles, ...), else its top-level subtree, else the
whole document. Unknown maps only widen the scope, never open a hole.

Claude-Session: https://claude.ai/code/session_01FeijYwkkKBqRx4GkS1BRGr
@Fafoooo
Fafoooo merged commit 7208610 into main Oct 10, 2026
8 checks passed
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