Skip to content

Harden Git commands used for disposable source downloads - #79067

Merged
pelikhan merged 6 commits into
mainfrom
pelikhan/safe-source-cloning
Nov 18, 2026
Merged

pelikhan merged 6 commits into
mainfrom
pelikhan/safe-source-cloning

Conversation

@pelikhan

Copy link
Copy Markdown
Collaborator

Source downloads should inspect repository content without executing hooks or commands inherited from the user's Git configuration.

Adds a shared isolated Git command builder and applies it to workflow-download and directory-listing clone fallbacks, including subsequent fetch, checkout, and tree-listing operations. It disables hooks, templates, fsmonitor, credential helpers, interactive prompts, and automatic maintenance; ignores inherited Git configuration overrides; and allows only HTTPS transport without redirects.

Authentication uses host-scoped gh tokens passed through the child environment, never command arguments or on-disk configuration. The bundled Git HTTPS transport remains available for relocatable installations. Development checkouts are unchanged; these source-download paths intentionally no longer support SSH, file transports, or custom credential helpers.

Validation

  • Authenticated HTTPS clone regression verifies hostile hooks, filters, templates, URL rewrites, and environment overrides do not execute or alter source content.
  • Executable transport rejection, gitutil tests, affected download tests, compile/vet, and WASM build passed.
  • make agent-report-progress remains blocked by pre-existing custom-linter findings in the touched files: function length, newline splitting, string-index analysis, and an unchecked response-body close. Standard Go lint and impacted tests passed.

Isolate Git configuration and environment, disable executable hooks and helpers, restrict transports to HTTPS, and preserve host-scoped gh authentication for source download fallbacks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review November 18, 2026 16:02
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 16:02
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by PR Specification Reviewer for #79067 · copilot · gpt56 · ~3 AIC · ⌖ ~2 AIC · ⊞ 1.7K · ◷

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~4 AIC · ⌖ ~2 AIC · ⊞ 1.5K · ◷

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by Ponytail Reviewer for #79067 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@github-actions

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR adds 182 lines in business-logic directories (pkg/) but has no linked ADR, so I pushed a draft ADR to the branch:

docs/adr/79067-isolate-git-commands-for-source-downloads.md (link unavailable: invalid HTTPS URL)

Decision inferred: route all Git operations on disposable source-download clones through gitutil.SourceCommandContext (HTTPS-only, ignoring user Git config/hooks/templates/credential helpers, host-scoped gh token via child env).

Next action: review the draft, resolve the [TODO: verify] items (deciders, rationale against a pure-Go Git alternative), and change status from Draft to Accepted/Proposed before merge. Please also review the Negative consequences, notably dropped SSH/file/custom credential-helper support and ignored global Git config on these paths.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: sonnet55 high · ~15 AIC · ⌖ ~2 AIC · ⊞ 8.6K · ◷
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-169e736a-4551-416c-9cbc-142739a8a508","parents":[],"payload":{"id":"ldg-550bec9c-26eb-43bf-b62a-24ac6c295c41","operation":"append","value":{"finding_count":0,"head_sha":"ec448fa87aedd5cfefd83010b6df497d470b37e5","outcome":"aligned"}},"sha":"sha256:932730cb046cc5b5f7b90ffea40fcf12fdf566e26fa29bb068a01c1eaf9ad984","timestamp":"2026-11-18T16:10:01.128Z","type":"ledger_append","version":1}
History

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-18T16:05:28Z
review_event: REQUEST_CHANGES
top_themes:
  - HTTPS redirect handling breaks renamed/transferred repository downloads
files_reviewed:
  - pkg/gitutil/source_command.go
  - pkg/cli/download_workflow.go
  - pkg/parser/remote_download_file.go
  - pkg/parser/remote_list_files.go
  - pkg/gitutil/source_command_test.go
  - pkg/gitutil/README.md
comment_count: 1
History

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~2 AIC · ⊞ 1.5K · ◷
Comment /review to run again

@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.

Found one blocking correctness regression: disabling all HTTPS redirects prevents downloads from renamed or transferred repositories, which GitHub serves via 301/302. The inline comment describes the failure and a compatible fix. Static review only; tests were not run per review instructions.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~2 AIC · ⊞ 1.5K
Comment /review to run again

Comment thread pkg/gitutil/source_command.go Outdated
"-c", "core.askPass=",
"-c", "protocol.allow=never",
"-c", "protocol.https.allow=always",
"-c", "http.followRedirects=false",

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.

Disabling all HTTP redirects breaks normal GitHub source downloads when a repository has been renamed or transferred: GitHub responds with a 301/302 for the old HTTPS URL, and Git will now fail instead of following it. This regresses the existing fallback paths for those repositories. Please preserve redirect-following for the initial request (for example, http.followRedirects=initial) or otherwise handle trusted HTTPS redirects explicitly, with a regression test.

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.

d9e6acf enables initial HTTPS redirects and adds a regression test for a renamed repository URL. The Git utility tests passed after updating from main.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-9b1b6260-bef7-4014-9087-bf862d026e54","parents":[],"payload":{"id":"ldg-9f8a1a33-98c2-4382-b7a6-1357867a0049","operation":"append","value":{"finding_count":1,"head_sha":"ec448fa87aedd5cfefd83010b6df497d470b37e5","outcome":"findings"}},"sha":"sha256:a274b96bcfb0039a0f28a8fde30a010008c72370769c294d88089ff9f893ac79","timestamp":"2026-11-18T16:11:55.631Z","type":"ledger_append","version":1}
History

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.

🟡 Changes recommended

Source-download isolation remains bypassable through checkout-local Git configuration and inherited GIT_EXEC_PATH overrides, which can select an untrusted transport helper that receives injected credentials.

4 open issues
What changed in this PR

Adds a shared Git command builder to isolate gh-aw’s disposable source downloads from user Git configuration, while leaving development checkouts unchanged.

Changes:

  • Adds HTTPS-only transport restrictions and environment-only gh authentication.
  • Migrates workflow downloads and directory-listing fallbacks to the shared builder.
  • Adds isolation regression tests and documents the helper’s contract.
File Description
pkg/​parser/​remote_list_files.go Uses isolated commands for listing clones and tree inspection.
pkg/​parser/​remote_download_file.go Uses isolated commands for archive, clone, and checkout fallbacks.
pkg/​gitutil/​source_command.go Introduces the shared command builder and credential handling.
pkg/​gitutil/​source_command_test.go Tests authenticated HTTPS cloning, hostile settings, and transport rejection.
pkg/​gitutil/​README.md Documents the API, isolation contract, and runtime requirements.
pkg/​cli/​download_workflow.go Applies the builder throughout workflow-download Git operations.

Review effort: Max (adaptive)

Comment thread pkg/gitutil/source_command.go Outdated
}
cmd := exec.CommandContext(ctx, "git", append(base, args...)...)
// Do not discover configuration in the caller's checkout.
cmd.Dir = os.TempDir()

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.

d9e6acf moves the default Git working directory outside the surrounding checkout and bounds repository discovery. The regression with TMPDIR inside a checkout passed.

Comment thread pkg/gitutil/source_command.go Outdated
Comment on lines +37 to +39
// Relocatable Git installations need their bundled HTTPS transport.
if (!strings.HasPrefix(strings.ToUpper(key), "GIT_") || key == "GIT_EXEC_PATH") && key != "SSH_ASKPASS" {
cmd.Env = append(cmd.Env, value)

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.

d9e6acf strips the inherited override and gets the helper directory from Git itself under the isolated environment. The Git utility regression tests passed.

Comment thread pkg/gitutil/source_command.go Outdated
}
cmd := exec.CommandContext(ctx, "git", append(base, args...)...)
// Do not discover configuration in the caller's checkout.
cmd.Dir = os.TempDir()

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.

d9e6acf switches all three clone call sites to the shared absolute temp-directory helper. The relative-TMPDIR regression passed.

Comment thread pkg/gitutil/source_command.go Outdated
Comment on lines +48 to +50
cmd.Env = append(cmd.Env, "GIT_CONFIG_COUNT=1",
"GIT_CONFIG_KEY_0=http."+remoteURL+".extraheader",
"GIT_CONFIG_VALUE_0=AUTHORIZATION: basic "+header)

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.

d9e6acf retries without the authorization header after authentication rejection. The regression verifies that a public clone succeeds despite a rejected token and that authenticated cloning still works.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/gitutil/source_command.go:27): address unresolved feedback - Review comment
  3. Review (pkg/gitutil/source_command.go:34): address unresolved feedback - Review comment
  4. Review (pkg/gitutil/source_command.go:39): address unresolved feedback - Review comment
  5. Review (pkg/gitutil/source_command.go:34): address unresolved feedback - Review comment
  6. Review (pkg/gitutil/source_command.go:50): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "90da77334be10dd7ecbc4f20ba0c1d308a8c2491",
  "kind": "requested",
  "schema_version": "1",
  "state": "9524c409f3f6535413864cd3f23812a5e165e9b875830745b367cf8a76a3c014",
  "work": [
    "665d84c56bac3539931948dc9d5f5dd8005b26db5df54987eb2185b5dc60086b",
    "6c8e0356dccdd8cda3f32188524e9b2d5b419a82b9e73ae5e7b3542a22f8f4b6",
    "78ab93dd8bb3c4d8c34c2b67acce7342aee0240f77df9c8406c5f1e7fecb402c",
    "870420d230d31860bdc6dde15cf99c0efd1693eeb96b6e6dfe6eca15e2f75b5d",
    "93b3043d9fab679ddd9e45335e87c533ba7f41f276242319a41b3d83d2bad5a8"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 7K · ◷
Comment /souschef to run again

gh-aw-bot and others added 2 commits November 18, 2026 17:00
…cloning

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot fix ci failures

…cloning

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

@copilot fix ci failures

60a2f65 fixes both Go lint failures. Updating from main in 42276ce brought in the permissions-policy fix. The corresponding tests and CI lint checks passed locally. The broader local gate still reports the pre-existing custom-lint findings, and CodeQL timed out.

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Updated the PR branch from main in 42276ce and verified all five review fixes from d9e6acf with the Git utility tests. No workflow was manually dispatched.

@pelikhan
pelikhan merged commit e4e1419 into main Nov 18, 2026
114 checks passed
@pelikhan
pelikhan deleted the pelikhan/safe-source-cloning branch November 18, 2026 21:12
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.

4 participants