Skip to content

feat: add trusted_bots parameter to support Dependabot PRs - #388

Closed
cansin wants to merge 8 commits into
anthropics:mainfrom
yellow-pine:fix/dependabot-token-permissions
Closed

cansin wants to merge 8 commits into
anthropics:mainfrom
yellow-pine:fix/dependabot-token-permissions

Conversation

@cansin

@cansin cansin commented Aug 3, 2025 •

Copy link
Copy Markdown

Fixes #387 , Addresses #195

Summary

Adds support for Dependabot and other automation bots to trigger Claude Code Action on pull requests when using external tokens (PAT or custom GitHub App).

Related Work

This PR addresses a similar goal as:

While these PRs take different approaches, they all aim to enable bot users to work with Claude Code Action. This PR specifically focuses on the Dependabot use case with a security-first approach.

Problem

Claude Code Action was checking if actors like dependabot[bot] are repository collaborators, which they never are. This caused all Dependabot PRs to fail even with valid tokens that have write permissions.

Solution

This PR introduces a trusted_bots parameter that allows specific bots to bypass actor permission checks under controlled conditions:

  • Token-First Validation: Always validates token permissions before checking actor permissions
  • Conditional Bypass: External tokens can specify trusted bots that bypass collaborator checks
  • Secure by Default: Empty trusted_bots list means all actors require full permission checks
  • Defense in Depth: Multiple security controls prevent abuse of the bypass mechanism

Key Differences from Other PRs

Usage

- uses: anthropics/claude-code-action@beta
  with:
    github_token: ${{ steps.app-token.outputs.token }}
    trusted_bots: |
      dependabot[bot]

Security Considerations

  • ✅ Only works on pull_request events (never pull_request_target)
  • ✅ External token must have repository write permissions
  • ✅ Bot must be the PR author (prevents confused deputy attacks)
  • ✅ Bot authenticity verified via sender type
  • ✅ OIDC tokens always require full actor verification
  • ✅ Empty trusted_bots by default (opt-in security)

Testing

Added comprehensive test coverage for all permission validation scenarios, including edge cases around token types, bot validation, and error handling. All new code has 100% test coverage.

Documentation

Updated the setup guide with a new "Working with Dependabot" section that explains configuration and security best practices.

Live Demonstration

Demo repository: https://github.com/yellow-pine/claude-action-dependabot-repro

  • PR #3 - Shows how this fix enables Claude Code Review on Dependabot PRs
  • PR #2 - Confirms the fix doesn't break regular user PRs

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

@cansin
cansin marked this pull request as draft August 3, 2025 09:57
@cansin cansin changed the title fix: check token permissions for external tokens instead of actor permissions (#387) fix: validate token permissions instead of actor permissions for external tokens Aug 3, 2025
@cansin
cansin marked this pull request as ready for review August 3, 2025 11:53
@cansin
cansin marked this pull request as draft August 3, 2025 11:56
@cansin
cansin marked this pull request as ready for review August 3, 2025 11:57
@cansin
cansin marked this pull request as draft August 3, 2025 11:57
@cansin cansin changed the title fix: validate token permissions instead of actor permissions for external tokens Fix Dependabot PR compatibility by validating token permissions Aug 3, 2025
@cansin
cansin marked this pull request as ready for review August 3, 2025 14:07
@cansin
cansin marked this pull request as draft August 4, 2025 03:22
@cansin cansin changed the title Fix Dependabot PR compatibility by validating token permissions Fix Dependabot PR support with token-based permission validation Aug 4, 2025
@cansin cansin changed the title Fix Dependabot PR support with token-based permission validation feat: add trusted_bots parameter to support Dependabot PRs Aug 4, 2025
@cansin cansin changed the title feat: add trusted_bots parameter to support Dependabot PRs feat: add trusted_bots parameter to support Dependabot PRs Aug 4, 2025
@cansin
cansin marked this pull request as ready for review August 4, 2025 07:51
lroolle added a commit to thevibeworks/claude-code-action that referenced this pull request Aug 4, 2025
- Add allow_bot_actor parameter to enable GitHub bots to trigger Claude Code Action
- Implement robust bot write permission validation
- Add test coverage for bot scenarios
- Update documentation with security considerations

This enables automated workflows like documentation updates, CI-triggered
code reviews, and scheduled maintenance while maintaining security through
explicit opt-in and proper permission validation.

Relevant works: anthropics#388 anthropics#280 anthropics#194 anthropics#117
@burkematthew

Copy link
Copy Markdown
Contributor

In case it's helpful, this may be a duplicate feature of #117.

@cansin

cansin commented Aug 4, 2025

Copy link
Copy Markdown
Author

@burkematthew you are right, I didn't realize it was! I'll let the contribs tell us what to do 😊

@cansin

cansin commented Aug 4, 2025

Copy link
Copy Markdown
Author

🎬 Live Demonstration

I've created a demonstration repository that validates this fix works correctly:

Demo Repository: https://github.com/yellow-pine/claude-action-dependabot-repro

Demo PRs:

  • ✅ PR #3 - Shows how this fix enables Claude Code Review on Dependabot PRs
  • ✅ PR #2 - Confirms the fix doesn't break regular user PRs

Key Validation Points:

  1. Dependabot Support: With trusted_bots: dependabot[bot], Dependabot PRs work correctly
  2. Security: The GitHub App token still requires proper write permissions
  3. Backwards Compatibility: User PRs continue to work without any changes
  4. Configuration: Simple one-line addition to existing workflows

The demo uses this branch (fix/dependabot-token-permissions) to show the solution in action. Both test cases pass successfully, demonstrating the fix resolves issue #387 without introducing regressions.

@ashwin-ant

Copy link
Copy Markdown
Collaborator

@cansin I'm not following what this PR is trying to do. It sounds like #117 does the same thing, right?

@cansin

cansin commented Aug 4, 2025 •

Copy link
Copy Markdown
Author

@ashwin-ant yes, exact same functionality, with different security characteristics is how I'd summarize it perhaps? (I've created this PR and the issue attached without realizing that prior work, despite trying to search for it. I guess wrong keywords.)

cansin added 6 commits August 4, 2025 16:48
- Add TokenContext to track token source (OIDC vs external)
- Implement standardized API error handling with executeApiCall
- Add trustedBots parameter to GitHub context
- Add constants for bot validation (BOT_SUFFIX, SENDER_TYPE_BOT)
…pport

- Add comprehensive actor validation with bot verification
- Implement token-first permission checks before actor validation
- Support trusted bots bypass for external tokens on pull_request events
- Add security validations: bot authenticity, PR authorship, event type
- Ensure OIDC tokens always require full actor verification
- Rename checkHumanActor to ensureAuthorizedActor for clarity
- Add trusted_bots input parameter to action.yml
- Support newline-separated list of trusted bot names
- Configure empty default for backward compatibility
- Pass parameter through to base action
- Update prepare entrypoint to use TokenContext
- Pass TokenContext to permission validation
- Update tag mode to use ensureAuthorizedActor
- Add getSystemPrompt method to mode interface
- Test OIDC vs external token permission flows
- Test trusted bot validation scenarios
- Test security edge cases and validation rules
- Add mock utilities for GitHub API responses
- Achieve 100% coverage for new validation logic
- Document trusted_bots parameter in usage guide
- Add 'Working with Dependabot' section to setup guide
- Include security best practices and warnings
- Update CLAUDE.md with authentication flow notes
- Add examples for Dependabot configuration
cansin

This comment was marked as outdated.

- Consolidate bot suffix and sender type validation into single check
- Use boolean comparison to detect mismatches between expected and actual bot status
- Maintain same security guarantees with cleaner, more readable code
lroolle added a commit to thevibeworks/claude-code-action that referenced this pull request Aug 5, 2025
- Add allow_bot_actor parameter to enable GitHub bots to trigger Claude Code Action
- Implement robust bot write permission validation
- Add test coverage for bot scenarios
- Update documentation with security considerations

This enables automated workflows like documentation updates, CI-triggered
code reviews, and scheduled maintenance while maintaining security through
explicit opt-in and proper permission validation.

Relevant works: anthropics#388 anthropics#280 anthropics#194 anthropics#117
lroolle added a commit to thevibeworks/claude-code-action that referenced this pull request Aug 6, 2025
- Add allow_bot_actor parameter to enable GitHub bots to trigger Claude Code Action
- Implement robust bot write permission validation
- Add test coverage for bot scenarios
- Update documentation with security considerations

This enables automated workflows like documentation updates, CI-triggered
code reviews, and scheduled maintenance while maintaining security through
explicit opt-in and proper permission validation.

Relevant works: anthropics#388 anthropics#280 anthropics#194 anthropics#117
@cansin

cansin commented Aug 6, 2025 •

Copy link
Copy Markdown
Author

@ashwin-ant looks like #117 is moving forward. I am closing this one to avoid any confusions. Please feel free to reach out if I can be of help.

@cansin cansin closed this Aug 6, 2025
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.

Claude Code Action incompatible with Dependabot PRs - actor permission check fails

3 participants