Skip to content

fix(safe-outputs): trust cross-repo checkout dirs from manifest (dubious ownership)#40080

Merged
dsyme merged 5 commits into
mainfrom
fix/checkout-manifest-safe-directory
Jun 18, 2026
Merged

fix(safe-outputs): trust cross-repo checkout dirs from manifest (dubious ownership)#40080
dsyme merged 5 commits into
mainfrom
fix/checkout-manifest-safe-directory

Conversation

@dsyme

@dsyme dsyme commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #40079.

Safe-outputs create_pull_request (and other git-running handlers) fail with Failed to pin branch '<branch>' when a workflow uses a cross-repository checkout into a subdirectory (e.g. ${GITHUB_WORKSPACE}/github). The branch exists locally, but git aborts the git rev-parse pinning command with "dubious ownership" because the subdirectory is a separate git repository that was never trusted as a safe.directory.

Root cause

actions/setup/sh/configure_git_credentials.sh only added GITHUB_WORKSPACE as a git safe.directory. The safe-outputs MCP server resolves cross-repo checkouts to subdirectories (repoCwd, from the checkout manifest) and runs git there — those directories were untrusted.

Fix

configure_git_credentials.sh now consults the checkout manifest ($RUNNER_TEMP/gh-aw/safeoutputs/checkout-manifest.json, or GH_AW_CHECKOUT_MANIFEST) and adds each recorded cross-repo checkout subdirectory (${GITHUB_WORKSPACE}/<path>) as a safe.directory, alongside the workspace itself.

  • Uses node (already present in both the agent job and the gh-aw-node container) to parse the JSON manifest.
  • Defensively rejects manifest paths that resolve outside the workspace (path traversal).
  • No-ops gracefully when the manifest, RUNNER_TEMP, or node are absent.

Tests

Added actions/setup/js/configure_git_credentials.test.cjs covering:

  • cross-repo subdirectories trusted from the manifest
  • empty-path entries skipped
  • path-traversal entries rejected
  • GH_AW_CHECKOUT_MANIFEST override honored
  • no-manifest case still succeeds

configure_git_credentials.sh now reads the checkout manifest and adds each
cross-repository checkout subdirectory as a git safe.directory. Without this,
safe-outputs handlers that run git inside those subdirectories (resolved via
repoCwd) fail with "dubious ownership", surfacing as "Failed to pin branch".

Fixes #40079
Copilot AI review requested due to automatic review settings June 18, 2026 14:22

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

This PR addresses safe-outputs failures when workflows perform cross-repository checkouts into workspace subdirectories by expanding git safe.directory configuration to include checkout subdirectories recorded in the checkout manifest, preventing “dubious ownership” errors during local git operations.

Changes:

  • Extend actions/setup/sh/configure_git_credentials.sh to parse the checkout manifest (optionally overridden via GH_AW_CHECKOUT_MANIFEST) and add each in-workspace checkout subdirectory to git config --global safe.directory.
  • Add Vitest coverage for manifest-based safe.directory behavior, including path traversal rejection and override support.
Show a summary per file
File Description
actions/setup/sh/configure_git_credentials.sh Adds manifest-driven safe.directory entries for cross-repo checkout subdirectories to avoid dubious ownership failures in safe-outputs handlers.
actions/setup/js/configure_git_credentials.test.cjs Adds unit tests validating safe.directory additions, traversal rejection, override behavior, and no-manifest behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread actions/setup/js/configure_git_credentials.test.cjs
Comment thread actions/setup/sh/configure_git_credentials.sh
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

CI lights the path
Green checks bloom at dawn
Quiet bots still sing

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

Generated by 🧪 Smoke CI for issue #40080 ·

dsyme and others added 3 commits June 18, 2026 15:33
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The autofix suggestion that added \r\n\0 path guards accidentally removed the
for-loop's closing brace, breaking the embedded node script so it threw and
trusted no cross-repo directories. This caused the configure_git_credentials
JS tests to fail in CI.
@dsyme dsyme merged commit a053bc9 into main Jun 18, 2026
33 checks passed
@dsyme dsyme deleted the fix/checkout-manifest-safe-directory branch June 18, 2026 14:46
@github-actions github-actions Bot mentioned this pull request Jun 19, 2026
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 PR creation fails with "Failed to pin branch" on cross-repo checkouts (git dubious ownership)

2 participants