fix: safe-outputs checkout auto-detection must not downgrade contents: write to read - #50907
Conversation
…: write to read Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot could not run the full agentic suite for this review because it was automatically requested on a bot-authored pull request. Request a review from Copilot under Reviewers to retry with the full agentic suite. Improved support for bot-authored pull requests is coming soon.
Prevent the safe-outputs permission auto-detection for actions/checkout from unintentionally reducing an already-required contents: write permission (e.g., from create-pull-request handling).
Changes:
- Add a regression test ensuring checkout detection does not downgrade
contents: writetocontents: read. - Update permission computation to only add
contents: readwhencontentsis not already set.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/safe_outputs_permissions_test.go | Adds coverage for “checkout must not downgrade contents permission”. |
| pkg/workflow/safe_outputs_permissions.go | Avoids overwriting an existing contents permission when checkout is detected. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 91688d14-6091-4c7c-a628-422564a7bbb9
|
@copilot Please refresh this PR branch if needed and run the
|
|
/matt |
|
|
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /codebase-design — approving with one minor documentation observation.
📋 Key Themes & Highlights
Summary
The fix is minimal, correct, and well-tested. The guard uses permissions.Get(PermissionContents) which correctly handles both explicit per-scope permissions and shorthands like write-all — a better choice than GetExplicit (which the PR description mistakenly names). See the inline comment for details.
Positive Highlights
- ✅ Regression test added before the fix is merged
- ✅ Accurate comment in source explaining why the guard is needed
- ✅ Minimal, surgical change — only the at-risk branch is guarded
- ✅ Test name reads as a specification and clearly documents the invariant
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 24.5 AIC · ⊞ 7.1K
Comment /matt to run again
|
🎉 This pull request is included in a new release. Release: |
When
actions/checkoutappears insafe-outputs.steps, the compiler auto-detects it and injectscontents: read— but was doing so unconditionally, overwriting a handler-derivedcontents: write(e.g., fromcreate-pull-request). The generated GitHub App token then lacked write access, causing 403s ongit pushand branch creation.Changes
safe_outputs_permissions.go: Guard the checkout auto-detection with aGetExplicit(PermissionContents)check. Only injectcontents: readwhen nocontentspermission is already set; a pre-existingwriteis preserved unchanged.safe_outputs_permissions_test.go: Regression testTestComputePermissionsForSafeOutputs_CheckoutDoesNotDowngradeContentsWrite— asserts thatcreate-pull-request+ a checkout step yieldscontents: write, notcontents: read.