EXP-23278: Fix duplicate Authorization header on recursive HTTPS clones - #93
Merged
Merged
Conversation
When subrepo auth runs over HTTPS token (GH_USER/GH_TOKEN or
S7_GIT_USER/S7_GIT_TOKEN), s7 injects its auth into the child git's
environment as GIT_CONFIG_* entries, appending past any GIT_CONFIG_COUNT
the environment already carried. Recursing into a nested s7 subrepo spawns
a fresh s7 process (via that subrepo's post-checkout hook) that inherits
this environment and appended its own copy on top. Because
http.<url>.extraheader is multi-valued in git, the child then sent two
identical Authorization headers, and GitHub rejected the request with
HTTP 400 ("Duplicate header: Authorization") — breaking every nested
clone/fetch (e.g. rd2 -> RDPDFKit -> SPFlounder -> Eigen). Top-level
clones were unaffected.
Make the auth-env builder idempotent: stamp S7_GIT_AUTH_INJECTED on the
environment it produces and, when an ancestor s7 already stamped it, reuse
that environment verbatim instead of layering a second extraheader.
Add tests for the marker stamp, reuse-on-inherited-env, and a multi-level
nesting chain asserting a single Authorization header survives.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
pastey
previously approved these changes
Jul 30, 2026
pastey
left a comment
Contributor
There was a problem hiding this comment.
Great fix.
One tiny suggestion on the tests. Up to you.
Comment on lines
+137
to
+142
| - (void)testStampsInjectedMarker { | ||
| NSDictionary<NSString *, NSString *> *const env = | ||
| [GitRepository gitHubTokenAuthTaskEnvironmentForUser:@"alice" token:@"abc" processEnvironment:@{}]; | ||
|
|
||
| XCTAssertEqualObjects(@"1", env[@"S7_GIT_AUTH_INJECTED"]); | ||
| } |
Contributor
There was a problem hiding this comment.
I think, this is an implementation detail. The other two tests are fine – they test the behaviour. This one – I would rather remove it.
Contributor
Author
There was a problem hiding this comment.
Makes sense, removed it 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When subrepo auth runs over HTTPS token (
GH_USER/GH_TOKENorS7_GIT_USER/S7_GIT_TOKEN), s7 injects its auth into the child git's environment asGIT_CONFIG_*entries, appending past anyGIT_CONFIG_COUNTthe environment already carried. Recursing into a nested s7 subrepo spawns a fresh s7 process (via that subrepo's post-checkout hook) that inherits this environment and appended its own copy on top. Becausehttp.<url>.extraheaderis multi-valued in git, the child then sent two identical Authorization headers, and GitHub rejected the request with HTTP 400 ("Duplicate header: Authorization") — breaking every nested clone/fetch. Top-level clones were unaffected.Make the auth-env builder idempotent: stamp
S7_GIT_AUTH_INJECTEDon the environment it produces and, when an ancestor s7 already stamped it, reuse that environment verbatim instead of layering a second extraheader.Add tests for the marker stamp, reuse-on-inherited-env, and a multi-level nesting chain asserting a single Authorization header survives.
Note
Medium Risk
Changes HTTPS token auth environment construction for child git processes; behavior is narrowed with an idempotency guard and covered by new tests, but mistakes could still break nested clones or auth in CI.
Overview
Fixes nested HTTPS subrepo clones failing with GitHub HTTP 400 (
Duplicate header: Authorization) when each nested s7 process appended anotherhttp.https://github.com/.extraheaderonto inheritedGIT_CONFIG_*env.gitHubTokenAuthTaskEnvironmentForUser:token:processEnvironment:now stampsS7_GIT_AUTH_INJECTED=1on the env it builds and, when that marker is already present, returns the inherited env unchanged instead of adding another Authorization header. Comments clarify that appending past existingGIT_CONFIG_COUNTis for foreign CI config, not nested s7 (nested case uses the marker).Tests expect the marker on first injection, document the CI append case, and add nested reuse plus multi-level chaining checks so only one Basic auth header remains.
Reviewed by Cursor Bugbot for commit dfb7fd4. Bugbot is set up for automated code reviews on this repo. Configure here.