Skip to content

Comments

Fix Claude Review error#1948

Merged
genedna merged 1 commit intoweb3infra-foundation:mainfrom
genedna:main
Feb 21, 2026
Merged

Fix Claude Review error#1948
genedna merged 1 commit intoweb3infra-foundation:mainfrom
genedna:main

Conversation

@genedna
Copy link
Member

@genedna genedna commented Feb 21, 2026

No description provided.

Signed-off-by: Quanyi Ma <eli@patch.sh>
Copilot AI review requested due to automatic review settings February 21, 2026 08:52
@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Claude finished @genedna's task in 2m 9s —— View job


Code Review: Fix Claude Review error

  • Gather context and understand the PR
  • Read the changed workflow file and diff
  • Perform code review
  • Post review feedback

This PR modifies .github/workflows/claude-review.yml to fix errors with Claude review for PRs, particularly involving fork repositories. Here's my analysis:


Summary of Changes

  1. Removed author association checks from the if condition
  2. Enhanced PR resolution to fetch and use the source repository (fork) alongside the SHA
  3. Added repository: parameter to the checkout step for proper fork checkout
  4. Added allowed_non_write_users: "*" to the Claude action
  5. Expanded tool permissions in claude_args

Issues Found

🔴 High: Overly Broad Tool Permissions

The claude_args change expands tool permissions dramatically:

# Before (specific, targeted)
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"

# After (very broad)
--allowedTools "mcp__github__,mcp__github_inline_comment__,Bash(gh)"
  • mcp__github__ is a wildcard granting access to all GitHub MCP tools (not just inline commenting), which could include creating/merging PRs, deleting branches, creating issues, etc.
  • Bash(gh) allows any gh CLI command, including gh api, gh pr merge, gh issue delete, etc.

Previously, only 3 specific read-like gh pr subcommands and one MCP tool were allowed. This change significantly expands the blast radius if Claude is ever misused. Consider a more targeted allowlist. Fix this →

🔴 High: Removed Author Association Check for pull_request_target

# Before
github.event_name == 'pull_request_target' &&
(
  github.event.pull_request.author_association == 'OWNER' ||
  ...
)

# After  
github.event_name == 'pull_request_target' ||

pull_request_target runs with the base repository's secrets (including ANTHROPIC_API_KEY), even for fork PRs. GitHub's own documentation warns this event is security-sensitive. By removing the association check, any external contributor's PR now unconditionally triggers Claude, consuming Anthropic API quota. Combined with allowed_non_write_users: "*", there is no restriction at the workflow level — all access control is delegated to the Claude action itself.

This may be intentional (relying on the action's own auth), but it represents a shift in trust model that should be documented.

🟡 Medium: allowed_non_write_users: "*" is Maximally Permissive

allowed_non_write_users: "*"

The wildcard * allows any GitHub user to trigger Claude via @claude comments. This could be exploited for API cost abuse or prompt injection attacks. Consider allowlisting specific users or only allowing the repository organization members.

🟡 Medium: PR_NUMBER from issue.number May be Empty for pull_request_target

PR_NUMBER=${{ github.event.issue.number }}

For pull_request_target events (auto-triggered on PR open), github.event.issue is not populated — the number should come from github.event.pull_request.number. If PR_NUMBER is empty here, the gh pr view call will fail and the step will silently produce empty outputs. The fallback chain in the checkout step may mask this failure.

Consider: PR_NUMBER=${{ github.event.issue.number || github.event.pull_request.number }} Fix this →


Positive Changes

✅ Fork Repository Resolution

The enhanced PR resolution using gh pr view with a Go template is a solid improvement. The null-safety for deleted fork repositories ({{if .headRepository}}...{{else}}MISSING{{end}}) is thoughtful, and the fallback to the base repository is a reasonable default.

✅ Checkout with Repository Parameter

Adding the repository: parameter to the checkout step properly handles fork PRs:

repository: ${{ steps.resolve-pr-ref.outputs.pr_repo || github.event.pull_request.head.repo.full_name || github.repository }}

The three-level fallback chain is well-designed for different event types.


Verdict

The fork checkout fix is a legitimate improvement and likely fixes the root cause of the "Claude Review error" referenced in the PR title. However, the security posture changes (removed author association checks, wildcard non-write users, and broad tool permissions) should be reviewed carefully by the repository maintainers to ensure the trade-offs are acceptable for this project.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the claude-review.yml GitHub Actions workflow to address Claude review execution errors by changing when the job runs, improving PR SHA/repo resolution for comment-triggered runs, and loosening Claude action constraints.

Changes:

  • Relaxed job trigger conditions for pull_request_target and @claude mentions.
  • Updated PR ref resolution to also capture the PR source repository and pass it into checkout.
  • Expanded Claude action configuration (allowed_non_write_users and tool allowlist).

# Restrict tools that Claude can use during the review
claude_args: |
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
--allowedTools "mcp__github__,mcp__github_inline_comment__,Bash(gh)"
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool allowlist is substantially broadened from specific gh pr ... subcommands and a single inline-comment tool to mcp__github__, mcp__github_inline_comment__, and Bash(gh) (any gh subcommand). This weakens the intended sandbox and increases blast radius if the action is ever mis-prompted or compromised. Prefer keeping the narrowest possible tool list (only the exact MCP functions and gh pr view/diff/comment subcommands that are required).

Suggested change
--allowedTools "mcp__github__,mcp__github_inline_comment__,Bash(gh)"
--allowedTools "mcp__github_inline_comment__,Bash(gh pr view),Bash(gh pr diff),Bash(gh pr comment)"

Copilot uses AI. Check for mistakes.
Comment on lines +36 to 46
# Run on PRs or when explicitly triggered via comments
if: |
(
github.event_name == 'pull_request_target' &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR'
)
) ||
github.event_name == 'pull_request_target' ||
(
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
contains(github.event.comment.body, '@claude') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
contains(github.event.comment.body, '@claude')
) ||
(
github.event_name == 'pull_request_review' &&
contains(github.event.review.body, '@claude') &&
(
github.event.review.author_association == 'OWNER' ||
github.event.review.author_association == 'MEMBER' ||
github.event.review.author_association == 'COLLABORATOR'
)
contains(github.event.review.body, '@claude')
)
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job-level if now runs for all pull_request_target events (including PRs from forks) without restricting to trusted author_association or explicit @claude opt-in. With pull-requests: write / issues: write permissions and a checked-out fork repo, this is a significant security expansion. Consider re-adding the trusted-author guard (OWNER/MEMBER/COLLABORATOR) and/or requiring an explicit trigger (label/comment) before running on untrusted PRs.

Copilot uses AI. Check for mistakes.
Comment on lines 39 to 42
(
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
contains(github.event.comment.body, '@claude') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
contains(github.event.comment.body, '@claude')
) ||
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For issue_comment events, this condition only checks for @claude in the comment body, so the workflow will also run for comments on issues (non-PRs). That can lead to confusing/no-op runs (no PR context to review) and unnecessary consumption of runner time. Gate the issue_comment branch on github.event.issue.pull_request at the job level (similar to the step-level guard), or explicitly exclude non-PR issues here.

Copilot uses AI. Check for mistakes.
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
allowed_non_write_users: "*"
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowed_non_write_users: "*" allows any non-write user to invoke the action. Combined with pull_request_target and write-scoped GITHUB_TOKEN permissions, this can let untrusted users trigger automated commenting on PRs/issues using repository credentials. Consider restricting this to a vetted allowlist (or remove it) and rely on author_association / explicit maintainer trigger instead.

Suggested change
allowed_non_write_users: "*"
allowed_non_write_users: ""

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b71fa79b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

uses: actions/checkout@v6
with:
# Checkout the PR source repository (fork) to ensure branches exist for the action
repository: ${{ steps.resolve-pr-ref.outputs.pr_repo || github.event.pull_request.head.repo.full_name || github.repository }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep origin on base repo when fetching pull refs

Setting actions/checkout to github.event.pull_request.head.repo.full_name makes origin point at the contributor fork, but this workflow still relies on pull refs from origin (the next step configures refs/pull/*/head and the comment notes the action fetches origin pull/N/head). For forked PRs, refs/pull/<n>/head exists on the base repository, not the fork, so review runs can still fail with missing remote refs.

Useful? React with 👍 / 👎.

Comment on lines +38 to +41
github.event_name == 'pull_request_target' ||
(
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
contains(github.event.comment.body, '@claude') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
contains(github.event.comment.body, '@claude')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reinstate trusted-user gate for workflow triggers

This condition now allows pull_request_target and @claude comment triggers from any author, while the job later injects secrets.ANTHROPIC_API_KEY and a write-capable GITHUB_TOKEN into the action. That lets untrusted external users trigger privileged, billable runs simply by opening/syncing a PR or posting @claude, which was previously blocked by author_association checks.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b71fa79b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

uses: actions/checkout@v6
with:
# Checkout the PR source repository (fork) to ensure branches exist for the action
repository: ${{ steps.resolve-pr-ref.outputs.pr_repo || github.event.pull_request.head.repo.full_name || github.repository }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep origin on base repo when fetching pull refs

Setting actions/checkout to github.event.pull_request.head.repo.full_name makes origin point at the contributor fork, but this workflow still relies on pull refs from origin (the next step configures refs/pull/*/head and the comment notes the action fetches origin pull/N/head). For forked PRs, refs/pull/<n>/head exists on the base repository, not the fork, so review runs can still fail with missing remote refs.

Useful? React with 👍 / 👎.

Comment on lines +38 to +41
github.event_name == 'pull_request_target' ||
(
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
contains(github.event.comment.body, '@claude') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
contains(github.event.comment.body, '@claude')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reinstate trusted-user gate for workflow triggers

This condition now allows pull_request_target and @claude comment triggers from any author, while the job later injects secrets.ANTHROPIC_API_KEY and a write-capable GITHUB_TOKEN into the action. That lets untrusted external users trigger privileged, billable runs simply by opening/syncing a PR or posting @claude, which was previously blocked by author_association checks.

Useful? React with 👍 / 👎.

@genedna genedna merged commit 8465977 into web3infra-foundation:main Feb 21, 2026
17 of 18 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