Skip to content

Commit 58282f5

Browse files
la14-1louisgvclaude
authored
fix: eliminate GitHub token temp file exposure in agent-setup (fixes #2462) (#2470)
Pass GITHUB_TOKEN directly via inline `export` in the remote SSH command instead of writing it to local/remote temp files. This removes the race condition window where tokens could be read from disk. Agent: code-health Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b393814 commit 58282f5

1 file changed

Lines changed: 1 addition & 25 deletions

File tree

packages/cli/src/shared/agent-setup.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,40 +240,16 @@ export async function offerGithubAuth(runner: CloudRunner): Promise<void> {
240240
}
241241

242242
let ghCmd = "curl --proto '=https' -fsSL https://openrouter.ai/labs/spawn/shared/github-auth.sh | bash";
243-
let localTmpFile = "";
244243
if (githubToken) {
245244
const escaped = githubToken.replace(/'/g, "'\\''");
246-
localTmpFile = join(getTmpDir(), `gh_token_${Date.now()}_${Math.random().toString(36).slice(2)}`);
247-
writeFileSync(localTmpFile, `export GITHUB_TOKEN='${escaped}'`, {
248-
mode: 0o600,
249-
});
250-
const remoteTmpFile = `/tmp/gh_token_${Date.now()}`;
251-
try {
252-
await runner.uploadFile(localTmpFile, remoteTmpFile);
253-
ghCmd = `. ${remoteTmpFile} && rm -f ${remoteTmpFile} && ${ghCmd}`;
254-
} catch {
255-
try {
256-
unlinkSync(localTmpFile);
257-
} catch {
258-
/* ignore */
259-
}
260-
localTmpFile = "";
261-
}
245+
ghCmd = `export GITHUB_TOKEN='${escaped}' && ${ghCmd}`;
262246
}
263247

264248
logStep("Installing and authenticating GitHub CLI on the remote server...");
265249
try {
266250
await runner.runServer(ghCmd);
267251
} catch {
268252
logWarn("GitHub CLI setup failed (non-fatal, continuing)");
269-
} finally {
270-
if (localTmpFile) {
271-
try {
272-
unlinkSync(localTmpFile);
273-
} catch {
274-
/* ignore */
275-
}
276-
}
277253
}
278254

279255
// Propagate host git identity to the remote VM

0 commit comments

Comments
 (0)