Repository navigation
Add setting_sources input and default base-action to user-only - #1115
km-anthropic wants to merge 6 commits into
Conversation
Adds an enable_all_project_mcp_servers action input so workflow authors explicitly opt in to auto-loading servers from the checkout's .mcp.json. The wrapper action keeps a 'true' default since it restores .mcp.json from the PR base ref before execution, so wrapper-action behavior is unchanged. Complements #1115 (setting_sources default). :house: Remote-Dev: homespace
|
@km-anthropic — bump on this one. Sister PR #1250 applies the same opt-in pattern to |
Project and local settings additively merge their permissions with whatever allowed_tools a workflow specifies. A workflow author writing a restrictive allowlist reasonably expects it to be the complete allow-set, but .claude/settings.json can silently expand it. Changes: - Add setting_sources as a first-class input to both actions (previously only reachable via --setting-sources in claude_args) - base-action now defaults to settingSources: ['user'] — workflows that want project/local settings must opt in explicitly - Main action defaults to 'user,project,local' since .claude/ is restored from the PR base branch before execution, so project settings are maintainer-trusted in that context - Precedence: setting_sources input > --setting-sources in claude_args > default Breaking change for base-action: workflows relying on .claude/settings.json being loaded automatically need to add setting_sources: 'user,project,local'. :house: Remote-Dev: homespace
- test-mcp-integration: opt in to project settings so .mcp.json is discovered - test-mcp-config-flag: replace removed mcp_config input with claude_args --mcp-config :house: Remote-Dev: homespace
6e27900 to
625ab08
Compare
Keeps the input default empty so claude_args --setting-sources is not shadowed; the wrapper applies user,project,local as the runtime fallback, base-action applies user. :house: Remote-Dev: homespace
Defaults to user-only under pull_request_target/workflow_run; otherwise keeps user,project,local. Wrapper's runtime default unchanged. :house: Remote-Dev: homespace
🏠 Remote-Dev: homespace
There was a problem hiding this comment.
Thanks — the README now has the "see below" paragraph and the issue_comment gating, so my earlier notes are addressed. I'm not auto-approving since this changes security-relevant setting-source defaults (and the wrapper's hardcoded defaultSettingSources bypasses the event gate by design); a maintainer should sign off on the defaults policy, ideally alongside #1250.
Extended reasoning...
Overview
This PR adds a setting_sources input to both action.yml and base-action/action.yml, threads it through run-claude.ts / index.ts / run.ts, and rewrites the settingSources resolution in parse-sdk-options.ts to a three-tier precedence (direct input → --setting-sources in claude_args → caller-supplied or event-gated default). It also updates the MCP integration tests and base-action README, and adds ~10 unit tests covering the new precedence and event gating.
Security risks
The core of this change is security-relevant: settingSources controls whether in-repo .claude/settings.json (which can additively expand the permission allowlist) is loaded. The base-action now defaults to ['user'] under pull_request_target / workflow_run / issue_comment, which is a hardening. However, the wrapper (src/entrypoints/run.ts) passes defaultSettingSources: ['user','project','local'] unconditionally, intentionally bypassing the event gate on the rationale that .claude/ is restored from the PR base branch first. That rationale is documented in the input description, but it is a security policy decision that should be confirmed by a maintainer rather than auto-approved.
Level of scrutiny
High. This is a behavior change to defaults that affect every consumer of both the base-action and the wrapper, touches the permission-loading surface, and the author has explicitly requested maintainer review and coordination with sister PR #1250. It is not a mechanical or obviously-correct change.
Other factors
- Both of my prior inline comments have been addressed: the YAML default is now empty (12f457a) so
claude_args --setting-sourcesis reachable, and the README's dangling "(see below)" now has a corresponding paragraph (added with 044a103). - Test coverage for the new precedence logic is solid, including the empty-string fallthrough case that mirrors the YAML default.
- No new bugs were found by the bug-hunting system on this revision.
- The author bumped a specific maintainer and asked to land this together with #1250, which further indicates human coordination is expected before merge.
…red from base 🏠 Remote-Dev: homespace
| // Only assert that project/local config is safe to load when it was actually | ||
| // restored from the base branch above. Otherwise leave undefined so | ||
| // parseSdkOptions applies its event-gated default. | ||
| defaultSettingSources: configRestoredFromBase | ||
| ? ["user", "project", "local"] | ||
| : undefined, |
There was a problem hiding this comment.
🔴 This regresses the common "@claude on a plain issue" flow: issue_comment on a non-PR issue has context.isPR === false, so configRestoredFromBase stays false, defaultSettingSources is left undefined, and parseSdkOptions applies the event-gated default of ['user'] — silently dropping .claude/settings.json and .mcp.json that loaded before this PR. The checkout there is the trusted default branch (and the issues event still gets project,local), so the restriction isn't security-motivated; consider also setting defaultSettingSources when isEntityContext(context) && !context.isPR.
Extended reasoning...
What the bug is
Commit b6dac6f changed the wrapper to only pass defaultSettingSources: ['user','project','local'] when configRestoredFromBase is true. That flag is only set inside the if (isEntityContext(context) && context.isPR) block. For an issue_comment event fired on a plain issue (the canonical "@claude please do X" tag-mode entry point), context.isPR is Boolean(payload.issue.pull_request) → false (src/github/context.ts:188). The block is skipped, configRestoredFromBase stays false, and defaultSettingSources is passed as undefined.
parseSdkOptions then falls through to the event-gated fallback: GITHUB_EVENT_NAME === 'issue_comment' matches, so settingSources resolves to ['user']. Before this PR the fallback was unconditionally ['user','project','local'], so this is a behavior regression.
Step-by-step proof
- User comments
@claude implement feature Xon issue GettingAPI Error: 404whenuse_bedrock: "true"#42 (not a PR). - GitHub fires
issue_commentwithpayload.issue.pull_requestundefined. parseGitHubContext→isPR = Boolean(undefined) = false.- run.ts:245 —
isEntityContext(context) && context.isPR→true && false→ block skipped;configRestoredFromBase = false. - run.ts:287 —
defaultSettingSources: false ? [...] : undefined→undefined. - parse-sdk-options.ts —
options.settingSourcesis""(falsy), no--setting-sourcesin claude_args,options.defaultSettingSourcesisundefined, so??falls through to the event check. process.env.GITHUB_EVENT_NAME === 'issue_comment'→ returns['user'].- Claude runs without loading
.claude/settings.json(project permissions/hooks) or.mcp.json.
Why nothing prevents it
The restoreConfigFromBase machinery exists to sanitize PR checkouts where .claude/ is attacker-controlled. For issue_comment on a plain issue, the checkout is the repo's default branch — trusted maintainer content — so there is nothing to restore from and no attacker-controlled config to defend against. The new gating conflates "config was restored from base" with "config is trusted", missing the case where the checkout is already the trusted base.
Why it looks unintentional
The issues event (opened/labeled/assigned) is not in the gated list and still gets ['user','project','local']. So adding the claude label to an issue loads project settings, but commenting @claude on the same issue does not. The action.yml description says the wrapper "applies the same event-gated default as base-action for other contexts" without calling out that this drops project/local for the most common tag-mode trigger.
Impact
Users who rely on .claude/settings.json for project-level permission allowlists, hooks, or .mcp.json MCP servers will see them silently stop working when @claude is invoked on plain issues. No error is surfaced — tools/hooks/servers just disappear.
How to fix
In run.ts, also pass defaultSettingSources: ['user','project','local'] for the non-PR entity path, e.g.:
defaultSettingSources:
configRestoredFromBase || (isEntityContext(context) && !context.isPR)
? ['user', 'project', 'local']
: undefined,
(or equivalently set a separate configIsTrusted flag that covers both "restored from base" and "checkout is the default branch").
Adds an enable_all_project_mcp_servers action input so workflow authors explicitly opt in to auto-loading servers from the checkout's .mcp.json. The wrapper action keeps a 'true' default since it restores .mcp.json from the PR base ref before execution, so wrapper-action behavior is unchanged. Complements #1115 (setting_sources default). :house: Remote-Dev: homespace
Changes the base-action default for
settingSourcesfrom["user","project","local"]to["user"], and adds asetting_sourcesinput so callers can opt back in to project/local settings.With the new default, project-level
.claude/settings.jsonis not read unless explicitly enabled. The MCP integration tests are updated to opt in viasetting_sources: "user,project"(for the.mcp.jsondiscovery test) and to useclaude_args: --mcp-config(for the flag test).