Repository navigation
security(workflows): restrict claude.yml to trusted actors only - #2602
Conversation
`claude.yml` triggers on @claude mentions in issue comments, PR review comments, PR reviews, and issue bodies — then checks out the source PR's HEAD (from a fork, when applicable) and runs anthropics/claude-code-action with elevated permissions: contents: write (can push to master) pull-requests: write (can merge PRs) issues: write id-token: write + ANTHROPIC_API_KEY secret + GITHUB_TOKEN Without an author_association guard, any external contributor could: 1. Open a PR from their fork containing malicious code. 2. Comment `@claude please fix this`. 3. The workflow checks out their fork's HEAD with all the above privileges, and either: a. PR code runs during the action's tool execution and pushes unauthorized commits to master, auto-merges PRs, or exfiltrates the ANTHROPIC_API_KEY / GITHUB_TOKEN, OR b. The attacker convinces Claude (via prompt injection in code comments / PR description) to do the same. The fix gates each trigger branch with a check against the source event's `author_association`, which GitHub computes server-side based on the actor's relationship to the repo: Trusted (allowed): OWNER, MEMBER, COLLABORATOR Untrusted (blocked): CONTRIBUTOR, FIRST_TIME_CONTRIBUTOR, FIRST_TIMER, NONE External PR authors will fall into one of the untrusted categories, so the job step that follows (which checks out their fork's HEAD) never runs. No functional change for repo maintainers — when an OWNER/MEMBER/ COLLABORATOR mentions @claude, the workflow runs exactly as before. Observed during the audit of PR #2592 (a third-party PR from swoboda1337). That PR did NOT exercise this path (no @claude mention) and was otherwise safe — `project_automation.yml` is the only other workflow using `pull_request_target` and it correctly does not check out PR code, so PR #2592 itself caused no leakage. But the latent exploit in `claude.yml` would have applied to any future PR that did contain an `@claude` mention from an external actor. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds a security gate to the Claude workflow trigger. The ChangesClaude workflow security gate
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Summary
Found during the security audit of PR #2592 (third-party PR from @swoboda1337). That PR itself was safe (no
@claudemention, and the one workflow usingpull_request_target—project_automation.yml— correctly does not check out PR code). But the audit surfaced a latent exploit inclaude.ymlthat would apply to any future PR with an@claudemention from an external actor.The exploit
claude.ymltriggers on@claudementions in issue comments, PR review comments, PR reviews, and issue bodies — then checks out the source PR's HEAD (from a fork, when applicable) and runsanthropics/claude-code-actionwith elevated permissions:Without an author_association guard, any external contributor could:
@claude please review this.Outcomes:
ANTHROPIC_API_KEY/GITHUB_TOKEN, ORFix
Add an
author_associationcheck to each trigger branch:GitHub computes
author_associationserver-side based on the actor's relationship to the repo:OWNER,MEMBER,COLLABORATORCONTRIBUTOR,FIRST_TIME_CONTRIBUTOR,FIRST_TIMER,NONEExternal PR authors fall into the bottom row, so the checkout step that follows their @claude mention never runs.
Test plan
if:syntax —contains(fromJSON('[...]'), value)is the standard GitHub expression form).if:to false and skip the job.Reference
author_association: https://docs.github.com/en/graphql/reference/enums#commentauthorassociationRefs PR #2592 security audit.
🤖 Generated with Claude Code
Summary by CodeRabbit