Skip to content

test: cover cross-host auth forwarding for submodule clones#515

Merged
mafredri merged 2 commits into
mainfrom
mafredri/485-submodule-crosshost-auth-test
May 22, 2026
Merged

test: cover cross-host auth forwarding for submodule clones#515
mafredri merged 2 commits into
mainfrom
mafredri/485-submodule-crosshost-auth-test

Conversation

@mafredri
Copy link
Copy Markdown
Member

Adds a test that verifies the SameHost auth gating in cloneSubmodule actually behaves as intended end-to-end. The submodule HTTP server is wrapped with an observer that records every request carrying an Authorization header; the same-host subtest expects auth to be forwarded, the cross-host subtest expects it to be withheld.

The cross-host case uses localhost for the URL in .gitmodules and 127.0.0.1 for the parent server's URL. Both resolve to the loopback interface so the submodule clone still succeeds, but SameHost compares hostname strings and reports a mismatch, so the auth must not be sent.

Covers the security half of mafredri's thread PRRT_kwDOJPSNMM5vAH0h, where mafredri asked whether the gittest helper should be expanded to exercise the auth-exfiltration guard.

Why this PR and not the changes I considered

I also investigated AMREM-7 (move cloneSubmodule over to go-git's native Submodule.Update()). go-git v5.16.5's Submodule.Init resolves relative URLs via transport.NewEndpoint, which absolutizes against CWD, so the v5 implementation is broken for https://parent + ../sibling style submodules. The v6 fix in go-git/go-git@0e6f8484 lives in Worktree.Submodules() and is not backported. We could pre-resolve URLs ourselves and call native Update, but in v5 SubmoduleUpdateOptions does not surface InsecureSkipTLS, CABundle, or ProxyOptions, and the internal fetchAndCheckout only forwards Auth and Depth to FetchContext. Going native silently drops self-signed-cert, corporate-CA, and proxy support for submodule fetches. Keeping the bespoke clone is the right call; the reasoning is the TLS/proxy regression, not the relative-URL bug bjornrobertsson cited in-thread.

🤖 This PR was created with the help of Coder Agents, and will be reviewed by a human. 🏂🏻

@mafredri mafredri marked this pull request as ready for review May 21, 2026 12:35
@mafredri mafredri requested a review from johnstcn May 21, 2026 12:35
Base automatically changed from 74-git-submodule-support to main May 22, 2026 08:12
@johnstcn
Copy link
Copy Markdown
Member

needs rebase

Add a TestCloneRepoSubmoduleHostAuth case that observes whether the
submodule HTTP server received an Authorization header. The same-host
subtest expects auth to be forwarded; the cross-host subtest uses
'localhost' for the .gitmodules URL (so SameHost compares as
mismatched) while both hosts still resolve to the loopback interface,
so the submodule server is reachable but should never see the parent
credentials.

Covers the security half of mafredri thread PRRT_kwDOJPSNMM5vAH0h.
@mafredri mafredri force-pushed the mafredri/485-submodule-crosshost-auth-test branch from 40ca764 to 9f1a99d Compare May 22, 2026 11:20
@mafredri mafredri merged commit 7ac38c1 into main May 22, 2026
4 checks passed
@mafredri mafredri deleted the mafredri/485-submodule-crosshost-auth-test branch May 22, 2026 11:40
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.

2 participants