Update scripts to read tokens more securely#3908
Merged
Merged
Conversation
Also allow specifying the token using an environment variable.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves credential handling for repository maintenance scripts by avoiding passing GitHub tokens via command-line arguments, and instead supporting token retrieval from stdin and environment variables.
Changes:
pr-checks/sync-checks.tsnow resolves tokens via--token-stdinorGH_TOKEN/GITHUB_TOKEN(with unit tests for the resolution logic).update-release-branch.pynow reads tokens fromGH_TOKEN/GITHUB_TOKEN, and theupdate-release-branchworkflow exportsGITHUB_TOKENinto the script environment.- Contributor documentation for regenerating required checks is updated to reflect the new token passing approach.
Show a summary per file
| File | Description |
|---|---|
| pr-checks/sync-checks.ts | Add token resolution via stdin/env and update CLI parsing to use --token-stdin. |
| pr-checks/sync-checks.test.ts | Add unit tests covering stdin/env token resolution and failure cases. |
| CONTRIBUTING.md | Update instructions to use --token-stdin and/or GH_TOKEN/GITHUB_TOKEN. |
| .github/workflows/update-release-branch.yml | Export GITHUB_TOKEN so update-release-branch.py can authenticate via env var. |
| .github/update-release-branch.py | Switch authentication to read token from environment variables (removing CLI token usage). |
Copilot's findings
Comments suppressed due to low confidence (1)
pr-checks/sync-checks.ts:305
optionshere is the rawparseArgs().valuesobject (with a"token-stdin"property) but is then passed around asOptions. This works today becausetokenStdinis optional and unused elsewhere, but it’s easy to accidentally start readingoptions.tokenStdinlater and getundefined. Consider constructing a properly shapedOptionsobject (includingtokenStdin: options["token-stdin"]) and passing that through the rest of the script.
// Find the check runs for the specified `ref` that we will later set as the required checks
// for the main and release branches.
const checkInfos = await getChecksFor(options, client, options.ref);
const checkNames = new Set(checkInfos.map((info) => info.context));
- Files reviewed: 5/5 changed files
- Comments generated: 2
Comment on lines
+46
to
+52
| async function readTokenFromStdin(): Promise<string> { | ||
| let token = ""; | ||
| process.stdin.setEncoding("utf8"); | ||
| for await (const chunk of process.stdin) { | ||
| token += chunk; | ||
| } | ||
| return token.trim(); |
mbg
approved these changes
May 15, 2026
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.
Also allow specifying tokens using an environment variable. This improves security.