Skip to content

fix: safe-outputs checkout auto-detection must not downgrade contents: write to read - #50907

Merged
pelikhan merged 5 commits into
mainfrom
copilot/fix-contents-permission-downgrade
Aug 7, 2026
Merged

fix: safe-outputs checkout auto-detection must not downgrade contents: write to read#50907
pelikhan merged 5 commits into
mainfrom
copilot/fix-contents-permission-downgrade

Conversation

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

When actions/checkout appears in safe-outputs.steps, the compiler auto-detects it and injects contents: read — but was doing so unconditionally, overwriting a handler-derived contents: write (e.g., from create-pull-request). The generated GitHub App token then lacked write access, causing 403s on git push and branch creation.

Changes

  • safe_outputs_permissions.go: Guard the checkout auto-detection with a GetExplicit(PermissionContents) check. Only inject contents: read when no contents permission is already set; a pre-existing write is preserved unchanged.
// Before — unconditional downgrade
if stepsRequireContentsRead(safeOutputs.Steps) {
    permissions.Set(PermissionContents, PermissionRead)
}

// After — skip if a stronger permission already exists
if stepsRequireContentsRead(safeOutputs.Steps) {
    if _, exists := permissions.GetExplicit(PermissionContents); !exists {
        permissions.Set(PermissionContents, PermissionRead)
    }
}
  • safe_outputs_permissions_test.go: Regression test TestComputePermissionsForSafeOutputs_CheckoutDoesNotDowngradeContentsWrite — asserts that create-pull-request + a checkout step yields contents: write, not contents: read.

…: write to read

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix safe-outputs checkout permission downgrade issue fix: safe-outputs checkout auto-detection must not downgrade contents: write to read Aug 6, 2026
@pelikhan
pelikhan marked this pull request as ready for review August 6, 2026 16:17
Copilot AI balanced review requested due to automatic review settings August 6, 2026 16:17
Copilot AI requested a review from pelikhan August 6, 2026 16:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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: write to contents: read.
  • Update permission computation to only add contents: read when contents is 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

Comment thread pkg/workflow/safe_outputs_permissions.go Outdated
Comment thread pkg/workflow/safe_outputs_permissions.go Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 91688d14-6091-4c7c-a628-422564a7bbb9
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please refresh this PR branch if needed and run the pr-finisher skill before handing back to maintainers.

Generated by 👨🍳 PR Sous Chef · pi · gpt-5.4
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.3 AIC · ⊞ 8.3K ·
Comment /souschef to run again

@pelikhan

pelikhan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

/matt

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Matt Pocock Skills Reviewer. Review the logs for details.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@pelikhan
pelikhan merged commit 023cd7c into main Aug 7, 2026
33 checks passed
Copilot stopped work on behalf of gh-aw-bot due to an error August 7, 2026 00:00
@pelikhan
pelikhan deleted the copilot/fix-contents-permission-downgrade branch August 7, 2026 00:00
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.0

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.

safe-outputs checkout auto-detection downgrades contents: write to read

4 participants