Skip to content

security(workflows): restrict claude.yml to trusted actors only - #2602

Merged
zackees merged 1 commit into
masterfrom
security/claude-yml-restrict-trusted-actors
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
security/claude-yml-restrict-trusted-actors

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Found during the security audit of PR #2592 (third-party PR from @swoboda1337). That PR itself was safe (no @claude mention, and the one workflow using pull_request_target — project_automation.yml — correctly does not check out PR code). But the audit surfaced a latent exploit in claude.yml that would apply to any future PR with an @claude mention from an external actor.

The exploit

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:

permissions:
  contents: write       # can push to master
  pull-requests: write  # can merge PRs
  issues: write
  id-token: write
  # + ANTHROPIC_API_KEY + 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 review this.
  3. The workflow checks out their fork's HEAD with all the above privileges and runs an LLM-driven action over it.

Outcomes:

  • 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 or PR description) to do the same.

Fix

Add an author_association check to each trigger branch:

if: |
  (github.event_name == 'issue_comment' &&
    contains(github.event.comment.body, '@claude') &&
    contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) ||
  (github.event_name == 'pull_request_review_comment' &&
    contains(github.event.comment.body, '@claude') &&
    contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) ||
  (github.event_name == 'pull_request_review' &&
    contains(github.event.review.body, '@claude') &&
    contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association)) ||
  (github.event_name == 'issues' &&
    (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) &&
    contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.issue.author_association))

GitHub computes author_association server-side based on the actor's relationship to the repo:

Category Allowed?
OWNER, MEMBER, COLLABORATOR ✅ yes
CONTRIBUTOR, FIRST_TIME_CONTRIBUTOR, FIRST_TIMER, NONE ❌ blocked

External PR authors fall into the bottom row, so the checkout step that follows their @claude mention never runs.

Test plan

  • YAML parses (per the if: syntax — contains(fromJSON('[...]'), value) is the standard GitHub expression form).
  • After merge, a future @claude mention from a repo maintainer should still trigger the workflow (no functional regression for the intended use case).
  • An external contributor's @claude mention on their own PR should evaluate the if: to false and skip the job.

Reference

Refs PR #2592 security audit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated internal automation workflow access verification requirements.

Review Change Stack

`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]>
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0040fca0-4a7b-445b-855d-22f22a2c52fd

📥 Commits

Reviewing files that changed from the base of the PR and between 217ec5b and 3ebc3bd.

📒 Files selected for processing (1)
  • .github/workflows/claude.yml

📝 Walkthrough

Walkthrough

The PR adds a security gate to the Claude workflow trigger. The claude job now requires both a @claude mention in the event payload AND that the triggering actor holds an OWNER, MEMBER, or COLLABORATOR association. The gate applies consistently across issue comments, pull request review comments, pull request reviews, and issue events.

Changes

Claude workflow security gate

Layer / File(s) Summary
Trusted-actor gating for @claude mentions
.github/workflows/claude.yml
Updated the job trigger logic to require both @claude mention and trusted actor status (OWNER, MEMBER, or COLLABORATOR), with consistent checks applied across issue_comment, pull_request_review_comment, pull_request_review, and issues events.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A mention of Claude, and a trust check takes guard,
No strangers may summon—the gate's doing hard!
OWNER, MEMBER, COLLABORATOR true,
Now safeguards the trigger across comments askew.
Security whispers, the workflow now stands,
Protected by author's own trusted hands. 🔐

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/claude-yml-restrict-trusted-actors

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 and usage tips.

@zackees
zackees merged commit cb7b51c into master May 30, 2026
1 check failed
@zackees
zackees deleted the security/claude-yml-restrict-trusted-actors branch August 21, 2026 19:16
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