Implement custom setCancelled function with self-cancellation for team member checks#773
Closed
Implement custom setCancelled function with self-cancellation for team member checks#773
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
pelikhan
reviewed
Sep 12, 2025
Collaborator
pelikhan
left a comment
There was a problem hiding this comment.
The step that checks membership must be moved into the "task" job instead. It must not be in the agentic job.
…cellation Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement a custom "setCancelled" function in the JavaScript helper that try to check team membership.
It uses self cancellation.
- async function so use await when calling
- make sure generated job permissions have actions: write
- use when "setCanc...
Implement custom setCancelled function with self-cancellation for team member checks
Sep 12, 2025
Collaborator
|
@copilot The step that checks membership must be moved into the "task" job instead. It must NOT be in the agentic job. |
Copilot stopped work on behalf of
pelikhan due to an error
September 12, 2025 14:52
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.
This PR implements a custom
setCancelledfunction that uses GitHub Actions API self-cancellation when team membership checks fail, replacing the defaultcore.setCancelled()behavior with proper workflow run termination.Problem
The existing team member check implementation used
core.setCancelled()which only marks the job as cancelled but doesn't actually terminate the workflow run. This could allow unauthorized users to potentially bypass security checks in certain scenarios.Solution
Custom Self-Cancellation Function
Implemented an async
setCancelledfunction that uses the GitHub Actions API to cancel the current workflow run:Automatic Actions Write Permissions
The workflow compiler now automatically adds
actions: writepermission to jobs that include team member checks, enabling the self-cancellation functionality:Enhanced Security Logic
Files Modified
pkg/workflow/js/check_team_member.cjs: Updated to use custom setCancelled functionpkg/workflow/js/check_permissions.cjs: Updated to use custom setCancelled functionpkg/workflow/compiler.go: Enhanced to addactions: writepermissions when neededpkg/workflow/*_test.go: Updated tests to reflect new permission behaviorExample Generated Workflow
Before:
After:
Testing
The implementation follows the exact pattern shown in the issue description and provides robust error handling with fallback mechanisms.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.contoso.com/tmp/go-build469955445/b278/cli.test -test.testlogfile=/tmp/go-build469955445/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)/tmp/go-build4026414863/b278/cli.test -test.testlogfile=/tmp/go-build4026414863/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)/tmp/go-build2149779089/b278/cli.test -test.testlogfile=/tmp/go-build2149779089/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.