Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Enable Claude Code Review for fork PRs with security controls

Manav Rathicc56bd370707
diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml
index 653bfbcdfc..18ec266156 100644
--- a/.github/workflows/claude-code-review.yml
+++ b/.github/workflows/claude-code-review.yml
@@ -1,22 +1,17 @@
name: Claude Code Review
on:
- pull_request:
+ pull_request_target:
types: [opened, synchronize]
- # Optional: Only run on specific file changes
- paths:
- - "**/*.ts"
- - "**/*.tsx"
- # - "src/**/*.js"
- # - "src/**/*.jsx"
jobs:
claude-review:
- # Optional: Filter by PR author
- # if: |
- # github.event.pull_request.user.login == 'external-contributor' ||
- # github.event.pull_request.user.login == 'new-developer' ||
- # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
+ # Only run for: owners, members, collaborators, and whitelisted contributors
+ if: |
+ github.event.pull_request.author_association == 'OWNER' ||
+ github.event.pull_request.author_association == 'MEMBER' ||
+ github.event.pull_request.author_association == 'COLLABORATOR' ||
+ contains(fromJSON('["neeraj-pilot"]'), github.event.pull_request.user.login)
runs-on: ubuntu-latest
permissions:
@@ -29,7 +24,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
- fetch-depth: 0
+ # IMPORTANT: Checkout the PR head ref from the fork for security
+ ref: ${{ github.event.pull_request.head.sha }}
- name: Run Claude Code Review
id: claude-review
diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml
index 61dbc9f983..6de8177e5d 100644
--- a/.github/workflows/claude.yml
+++ b/.github/workflows/claude.yml
@@ -28,7 +28,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
- fetch-depth: 0
+ # For PR comments, checkout the PR head; otherwise checkout default branch
+ ref: ${{ github.event.issue.pull_request && format('refs/pull/{0}/head', github.event.issue.number) || github.ref }}
- name: Run Claude Code
id: claude
diff --git a/.github/workflows/security-check-workflows.yml b/.github/workflows/security-check-workflows.yml
new file mode 100644
index 0000000000..0538f475de
--- /dev/null
+++ b/.github/workflows/security-check-workflows.yml
@@ -0,0 +1,62 @@
+name: Security - Check Workflows
+
+on:
+ pull_request:
+ paths:
+ - '.github/workflows/**'
+
+jobs:
+ check-pull-request-target:
+ runs-on: ubuntu-latest
+ environment:
+ name: workflow-security-review
+ # This requires admin approval in repository settings
+ steps:
+ - name: Checkout PR
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Check for pull_request_target in modified workflows
+ run: |
+ # Get list of modified workflow files
+ MODIFIED_WORKFLOWS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^\.github/workflows/.*\.yml$' || true)
+
+ if [ -z "$MODIFIED_WORKFLOWS" ]; then
+ echo "No workflow files modified"
+ exit 0
+ fi
+
+ echo "Checking modified workflows: $MODIFIED_WORKFLOWS"
+
+ # Check if any modified workflow introduces pull_request_target
+ VIOLATIONS=""
+ for file in $MODIFIED_WORKFLOWS; do
+ if git show HEAD:$file | grep -q "pull_request_target:"; then
+ # Check if it existed in base branch
+ if git show origin/${{ github.base_ref }}:$file 2>/dev/null | grep -q "pull_request_target:"; then
+ echo "βœ“ $file: pull_request_target already existed (allowed)"
+ else
+ echo "βœ— $file: NEW pull_request_target trigger detected!"
+ VIOLATIONS="$VIOLATIONS\n- $file"
+ fi
+ fi
+ done
+
+ if [ -n "$VIOLATIONS" ]; then
+ echo ""
+ echo "❌ ERROR: New pull_request_target triggers detected in:$VIOLATIONS"
+ echo ""
+ echo "pull_request_target is a security-sensitive trigger that:"
+ echo "- Runs in the context of the base repository"
+ echo "- Has access to repository secrets"
+ echo "- Can be exploited by malicious PRs"
+ echo ""
+ echo "If you need to add pull_request_target, please:"
+ echo "1. Discuss with maintainers first"
+ echo "2. Ensure proper security measures are in place"
+ echo "3. Get explicit approval before merging"
+ exit 1
+ fi
+
+ echo "βœ“ No new pull_request_target triggers detected"