Skip to content

Commit cff8d3c

Browse files
authored
fix(git-config): neutralize checkout credential in include-based config (#1526)
configureGitAuth() removed the actions/checkout auth header with `git config --unset-all http.<server>/.extraheader`, which only edits the repo-local config. Since actions/checkout v6.0.0 (backported to v5.0.1 and v4.3.1) the header is written to a separate file under RUNNER_TEMP and pulled in via include.path, so --unset-all on the local config is a no-op: the code logged "No existing authentication headers to remove" while the checkout credential (usually the workflow GITHUB_TOKEN) stayed usable by git for the rest of the job. Also clear the header from every included file, so it is neutralized under both the pre-v6 (local) and v6+ (include) layouts. Includes that do not define the header are left untouched. Fixes #1510
1 parent e2a4b76 commit cff8d3c

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

‎src/github/operations/git-config.ts‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ export async function configureGitAuth(
5656
* action's own token instead (a credential helper when non-write users are
5757
* allowed, otherwise the origin URL). This applies to every mode, including API
5858
* commit signing where no other git configuration is needed.
59+
*
60+
* actions/checkout < v6 stored the header directly in the repo-local config,
61+
* where `git config --unset-all` removes it. Since v6.0.0 (backported to
62+
* v5.0.1 and v4.3.1) the header is written to a separate file under
63+
* RUNNER_TEMP that the repo config pulls in via `include.path`; `--unset-all`
64+
* on the local config cannot touch an include-provided value, so the removal
65+
* was a silent no-op and the checkout credential (typically the workflow
66+
* GITHUB_TOKEN) stayed usable by git for the rest of the job. Clear the
67+
* header from the local config AND from every included file so it can no
68+
* longer authenticate while Claude runs.
5969
*/
6070
export async function replaceCheckoutCredentials(
6171
githubToken: string,
@@ -65,12 +75,35 @@ export async function replaceCheckoutCredentials(
6575

6676
// Remove the authorization header that actions/checkout sets
6777
console.log("Removing existing git authentication headers...");
78+
const extraheaderKey = `http.${GITHUB_SERVER_URL}/.extraheader`;
79+
let removedHeader = false;
80+
try {
81+
await $`git config --unset-all ${extraheaderKey}`;
82+
removedHeader = true;
83+
} catch {
84+
// No extraheader in the local config (expected on the v6+ include layout).
85+
}
6886
try {
69-
await $`git config --unset-all http.${GITHUB_SERVER_URL}/.extraheader`;
70-
console.log("✓ Removed existing authentication headers");
71-
} catch (e) {
72-
console.log("No existing authentication headers to remove");
87+
const includePaths =
88+
await $`git config --local --get-all include.path`.text();
89+
for (const includePath of includePaths.split("\n")) {
90+
const path = includePath.trim();
91+
if (!path) continue;
92+
try {
93+
await $`git config --file ${path} --unset-all ${extraheaderKey}`;
94+
removedHeader = true;
95+
} catch {
96+
// This include does not define the header; leave it untouched.
97+
}
98+
}
99+
} catch {
100+
// No include.path entries in the local config.
73101
}
102+
console.log(
103+
removedHeader
104+
? "✓ Removed existing authentication headers"
105+
: "No existing authentication headers to remove",
106+
);
74107

75108
if (process.env.ALLOWED_NON_WRITE_USERS) {
76109
// When processing content from non-write users, use a credential helper

0 commit comments

Comments
 (0)