Prevent workflow_run triggers from executing in forked repositories#4070
Merged
Prevent workflow_run triggers from executing in forked repositories#4070
Conversation
- Update buildWorkflowRunRepoSafetyCondition to check repository.fork field - Generated condition now prevents execution from forked repositories - Add test verification for fork check presence - Update documentation to reflect fork prevention - All existing tests pass with new security enhancement Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- New TestWorkflowRunForkCheckPresent test verifies fork check presence - Validates NOT operator is applied to repository.fork field - Ensures AND operator combines repository ID and fork checks - All workflow_run tests pass successfully Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update generated code for workflow_run trigger
Prevent workflow_run triggers from executing in forked repositories
Nov 15, 2025
pelikhan
approved these changes
Nov 15, 2025
Contributor
|
Agentic Changeset Generator triggered by this pull request. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the security of workflow_run triggers by adding fork detection to prevent malicious actors from modifying workflows in forks and triggering them via workflow_run events. The existing repository ID check prevented cross-repository attacks but didn't prevent execution when both the triggering and receiving workflows were in the same fork.
Key Changes:
- Added
!github.event.workflow_run.repository.forkcheck combined with existing repository ID validation using AND logic - Updated generated conditions to require both repository ID match and non-fork status
- Enhanced test coverage with fork detection verification
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/role_checks.go | Implements fork detection by adding NotNode check on repository.fork property, combining it with existing repository ID check using AND logic |
| pkg/workflow/workflow_run_repo_safety_test.go | Adds comprehensive test assertions verifying fork check presence, NOT operator usage, and proper combination with repository ID check via AND operator |
| docs/src/content/docs/reference/triggers.md | Updates trigger documentation to mention fork validation alongside repository validation |
| docs/src/content/docs/guides/security.md | Updates security guide with detailed explanation of fork prevention, including code examples and security benefits |
| .github/workflows/dev-hawk.lock.yml | Regenerated lock file with new fork check in activation job condition |
| .github/workflows/ci-doctor.lock.yml | Regenerated lock file with new fork check in activation job condition |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
workflow_run triggers checked repository ID match but allowed execution in forks since IDs matched within the fork context. This created a security gap where malicious actors could modify workflows in forks and trigger them via workflow_run events.
Changes
!github.event.workflow_run.repository.forkcheck combined with existing repository ID validation using AND logicTestWorkflowRunForkCheckPresenttestGenerated Condition
Before:
After:
The condition now requires both repository ID match (cross-repo protection) and non-fork status (fork protection) for workflow_run events, while allowing all other event types through unchanged.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.