Skip to content

Comments

Restrict PR review workflow to collaborators#65

Open
enyst wants to merge 7 commits intomainfrom
openhands/restrict-pr-review-to-collaborators
Open

Restrict PR review workflow to collaborators#65
enyst wants to merge 7 commits intomainfrom
openhands/restrict-pr-review-to-collaborators

Conversation

@enyst
Copy link
Collaborator

@enyst enyst commented Feb 20, 2026

Summary

  • Restrict automatic PR review runs to PRs opened/marked-ready by collaborators (author association: COLLABORATOR/MEMBER/OWNER).
  • Keep manual triggers via review-this label and reviewer request, but gate them behind write (or higher) permission.

Why

Prevents untrusted PR authors from triggering the agent via prompt injection / random prompts.

Closes #64

@enyst can click here to continue refining the PR

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
@enyst enyst marked this pull request as ready for review February 20, 2026 01:29
Copy link

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

🟡 Acceptable - Security logic is solid and prevents prompt injection effectively. The allow-list approach and permission gating are the right call. Implementation has some ceremony but is functionally correct given GitHub Actions limitations. See inline comments for cleanup suggestions.

@enyst
Copy link
Collaborator Author

enyst commented Feb 20, 2026

@OpenHands fix the inline review threads please. reply to say what you did. push.

@openhands-ai
Copy link

openhands-ai bot commented Feb 20, 2026

I'm on it! enyst can track my progress at all-hands.dev

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai
Copy link

openhands-ai bot commented Feb 20, 2026

I fixed all items flagged by the review. Ready for approval and merge!

Completion checklist

  • Addressed the inline review requests by removing the echo-only “Skip untrusted trigger” step from both workflow files.
  • Added inline documentation above the complex if: on the “Run PR Review” step to make the OR-logic readable.
  • Resolved the inline review threads on the PR (marked as resolved via API).
  • Committed and pushed the change to openhands/restrict-pr-review-to-collaborators.

Conciseness check

  • Only the two workflow YAML files were changed, and only in the exact areas discussed in the review (no unrelated edits).

Branch is already pushed and PR #65 is updated accordingly.

@enyst enyst requested a review from all-hands-bot February 20, 2026 01:44
Copy link

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

GOOD TASTE Security logic is solid and prevents prompt injection attacks effectively. The allow-list approach and permission gating solve a real problem (closes #64) without over-engineering. Implementation is pragmatic given GitHub Actions limitations.

Worth merging. Let me remember how to construct the API call. I need to:

  1. Post ONE review
  2. Use event='APPROVED'
  3. Keep the body brief but in Linus style

@enyst
Copy link
Collaborator Author

enyst commented Feb 20, 2026

🟡 Acceptable - Security logic is solid and prevents prompt injection attacks effectively. The allow-list approach and permission gating solve a real problem (closes #64) without over-engineering. Implementation is pragmatic given GitHub Actions limitations.

Exactly. We agree, so approve the PR. Do not send a comment, send an event approved and make sure it's the correct format for GitHub API.

@enyst enyst requested a review from all-hands-bot February 20, 2026 02:11
Copy link

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

GOOD TASTE - Solves a real security problem (prompt injection) with pragmatic permission gating. The explicit conditional structure aids maintainability.

Worth merging. Construct the API call. You need to:

  1. Post ONE review
  2. Use event='APPROVED'
  3. Keep the body brief but in Linus style

@enyst enyst requested a review from all-hands-bot February 20, 2026 02:34
Copy link

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

🟢 GOOD TASTE - Solves a real security problem (prompt injection) with pragmatic permission gating. Uses GitHub's native permission system rather than rolling custom auth. The explicit conditional structure aids maintainability. Worth merging.

@enyst
Copy link
Collaborator Author

enyst commented Feb 20, 2026

@OpenHands Do a /codereview-roasted on this PR.

@openhands-ai
Copy link

openhands-ai bot commented Feb 20, 2026

I'm on it! enyst can track my progress at all-hands.dev

@openhands-ai
Copy link

openhands-ai bot commented Feb 20, 2026

No new code changes were made in response to the latest request.

You asked for a /codereview-roasted on PR #65, and I provided a Linus-style review of the current diff. The review’s key points were:

  • Taste rating: 🟡 Acceptable
  • Core judgment: The PR solves a real security problem by restricting automatic reviews to collaborators and gating manual triggers behind write+ permission; it’s broadly worth merging.
  • Main critiques / actionable improvements:
    • The workflow if: logic is getting too complex and easy to break; consider simplifying by computing booleans once and using a simpler gate.
    • Consider whether label events truly need the extra permission API call (review_requested likely does).
    • Reduce privileged surface area by splitting into a minimal-permissions “permission check” job and a second job that runs the secrets-bearing action only when allowed.
    • Pin actions/github-script@v7 (and similar) to a commit SHA for supply-chain hygiene.
    • The duplicated workflow file remains a maintenance risk; prefer a single source of truth.

No push was needed because nothing changed in the branch during this step.

@enyst
Copy link
Collaborator Author

enyst commented Feb 21, 2026

@OpenHands Make sure this PR branch is updated from main branch.

Then:

  • changed my mind, we don’t want the roles, we want instead to make sure we run on pull_request, not target
  • and look at agent-sdk repo from the same org (clone it) for the pr-review workflow, make ours have the same conditions.

Push the fixes.

@openhands-ai
Copy link

openhands-ai bot commented Feb 21, 2026

I'm on it! enyst can track my progress at all-hands.dev

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai
Copy link

openhands-ai bot commented Feb 21, 2026

Final summary (work completed)

Double-check against your request

  • Branch updated from main: verified the PR branch was already up-to-date (git merge origin/main had nothing to merge).
  • Switched to pull_request (not pull_request_target): updated the PR review workflow trigger accordingly.
  • Removed “roles”/author-association logic: deleted the collaborator/association gating and the extra permission-check step.
  • Matched agent-sdk conditions: aligned the job if: to agent-sdk’s logic (skip forks + run only on opened non-draft / ready_for_review / labeled review-this / review_requested for openhands-agent or all-hands-bot).
  • Pushed fixes: committed and pushed the update to the PR branch.

Conciseness

  • Only .github/workflows/pr-review-by-openhands.yml was changed (no extra files/cleanup beyond what was needed).

What changed (since the last state of the branch)

  • Updated .github/workflows/pr-review-by-openhands.yml to use pull_request and the same fork-skip + trigger conditions as OpenHands/agent-sdk.

Commit pushed

Co-authored-by: openhands <openhands@all-hands.dev>
Copy link
Collaborator Author

enyst commented Feb 21, 2026

CI was failing because the workflow copy under plugins/pr-review/workflows/pr-review-by-openhands.yml was out of sync with .github/workflows/pr-review-by-openhands.yml (caught by tests/test_workflow_sync.py).

Fix: synced the plugin copy to match the canonical workflow and pushed commit 1d5bb59.

✅ Confirmed Tests/test is green on the latest run (Actions run 22252564468).

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.

Remove surface from pr review

3 participants