Conversation
|
@copilot the condition applies when the workflow event type is workflow run. The check should be added if the agentic workflow declares a workflow run trigger. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot keep working |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot the condition should only apply when the event type is workflow run triggered actions. Update expression. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated the safety condition to only apply when the event type is workflow_run. The condition now checks both Example generated condition: if: ${{ (github.event_name == 'workflow_run') && (github.event.workflow_run.repository.id == github.repository_id) }}Commit: e3d9291 |
|
@copilot the condition should be (event type != workflow run) or (check repository if) |
…repo matches) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated the safety condition to use OR logic as requested. The condition is now: if: ${{ (github.event_name != 'workflow_run') || (github.event.workflow_run.repository.id == github.repository_id) }}This allows all non-workflow_run events while requiring repository match for workflow_run events. Commit: d0d378f |
…ow-trigger-restrictions
|
@copilot the condition should be included in the workflow level if field expression. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated to include the workflow_run safety check in the workflow-level if field expression ( The condition now appears on jobs that use the workflow-level if field: jobs:
activation:
if: >
(github.event.workflow_run.conclusion == 'failure') && ((github.event_name != 'workflow_run') || (github.event.workflow_run.repository.id == github.repository_id))Commit: f47d4df |
|
@copilot correction: the condition should be applied exclusively on the activation job. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated to apply the workflow_run safety check exclusively to the activation job. The safety check is no longer applied to pre-activation or main jobs. Example output: jobs:
activation:
if: >
(user_condition) && ((github.event_name != 'workflow_run') || (github.event.workflow_run.repository.id == github.repository_id))
agent:
needs: activation # No if conditionSince all jobs depend on activation (directly or indirectly), the safety check protects the entire workflow while being applied in only one location. Commit: 3033c6b |
|
@copilot merge main, recompile, review changes and improve if needed |
Main branch was already merged in commit 0235f66. All 67 workflows have been recompiled successfully. The implementation is complete and all tests pass. The workflow_run safety check is working correctly:
All validations pass:
Merged main branch and recompiled all workflows. Implementation is working correctly:
No improvements needed - the implementation is correct and complete. Commit: Already merged (0235f66) and recompiled (no changes) |
There was a problem hiding this comment.
Pull Request Overview
This PR adds repository safety checks for workflows triggered by workflow_run events to prevent cross-repository workflow_run attacks. The safety check ensures that workflow_run events only execute if they originate from the same repository by validating github.event.workflow_run.repository.id == github.repository_id.
Key changes:
- Adds automatic repository safety condition to activation jobs for workflows with
workflow_runtriggers - Combines user-specified
ifconditions with the safety check using AND logic - Updates existing workflow lock files to include the new safety condition
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/role_checks.go |
Adds functions to detect workflow_run triggers, build safety conditions, and combine them with existing conditions |
pkg/workflow/compiler_jobs.go |
Integrates workflow_run safety checks into the activation job compilation |
pkg/workflow/compiler_yaml.go |
Adds comment explaining that workflow-level if conditions are not supported |
pkg/workflow/workflow_run_repo_safety_test.go |
Comprehensive test suite for the workflow_run safety feature |
pkg/workflow/task_job_if_condition_test.go |
Updates existing tests to account for the new safety conditions |
.github/workflows/*.lock.yml |
Regenerated lock files with the new safety conditions applied |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| safetyNode := &ExpressionNode{Expression: unwrappedSafety} | ||
|
|
||
| combinedExpr := buildAnd(existingNode, safetyNode) | ||
| return combinedExpr.Render() |
There was a problem hiding this comment.
The combined expression is returned without the ${{ }} wrapper. While this works for long expressions that get converted to multiline format (which doesn't need the wrapper), short combined expressions will be invalid when rendered as single-line if conditions. The function should re-wrap the result: return fmt.Sprintf(\"${{ %s }}\", combinedExpr.Render())
| return combinedExpr.Render() | |
| return fmt.Sprintf("${{ %s }}", combinedExpr.Render()) |
Workflows triggered by
workflow_runevents can be exploited by malicious repositories to execute code in your context. This adds automatic repository ID validation to prevent cross-repository attacks.Changes
Core Implementation (
pkg/workflow/compiler_jobs.go,pkg/workflow/role_checks.go)workflow_runtriggers in agentic workflow frontmatter (markdown files)(github.event_name != 'workflow_run') || (github.event.workflow_run.repository.id == github.repository_id)Testing (
pkg/workflow/workflow_run_repo_safety_test.go,task_job_if_condition_test.go)Example
Before:
After:
The safety condition ensures that:
The condition is applied exclusively to the activation job. All other jobs depend on the activation job and therefore inherit the protection through job dependencies.
All workflows with
workflow_runtriggers declared in their frontmatter have been recompiled with the safety check applied.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.