fix: use core.getBooleanInput() to retrieve boolean input values (#223)

This PR switches from evaluating values passed to `skip-token-revoke` as
true if they are truthy in JavaScript, to using `getBooleanInput`. This
change ensures that only proper YAML boolean values are recognized,
preventing unintended evaluations to true.
- The definition of `getBooleanInput` is here: definition of
`core#getBooealnInput` is here:
https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/core/src/core.ts#L188-L208

The documentation states, `"If truthy, the token will not be revoked
when the current job is complete"`, so this change could be considered a
breaking change. This means that if there are users who rely on `truthy`
and expect values like whitespace or `"false"` to be evaluated as true
(though this is likely rare), it would be a breaking change.
- `Boolean(" ")` and `Boolean("false")` are both evaluated as true.

Alternatively, it can simply be considered a fix. How to handle this is
up to the maintainer.

Resolves https://github.com/actions/create-github-app-token/issues/216
This commit is contained in:
Yuta Kasai
2025-04-26 03:59:34 +09:00
committed by GitHub
parent 9ba274d954
commit c3c17c79cc
9 changed files with 17 additions and 5 deletions
+2 -2
View File
@@ -343,7 +343,7 @@ The reason we define one `permision-<permission name>` input per permission is t
### `skip-token-revoke` ### `skip-token-revoke`
**Optional:** If truthy, the token will not be revoked when the current job is complete. **Optional:** If true, the token will not be revoked when the current job is complete.
### `github-api-url` ### `github-api-url`
@@ -370,7 +370,7 @@ The action creates an installation access token using [the `POST /app/installati
1. The token is scoped to the current repository or `repositories` if set. 1. The token is scoped to the current repository or `repositories` if set.
2. The token inherits all the installation's permissions. 2. The token inherits all the installation's permissions.
3. The token is set as output `token` which can be used in subsequent steps. 3. The token is set as output `token` which can be used in subsequent steps.
4. Unless the `skip-token-revoke` input is set to a truthy value, the token is revoked in the `post` step of the action, which means it cannot be passed to another job. 4. Unless the `skip-token-revoke` input is set to true, the token is revoked in the `post` step of the action, which means it cannot be passed to another job.
5. The token is masked, it cannot be logged accidentally. 5. The token is masked, it cannot be logged accidentally.
> [!NOTE] > [!NOTE]
+2 -1
View File
@@ -18,8 +18,9 @@ inputs:
description: "Comma or newline-separated list of repositories to install the GitHub App on (defaults to current repository if owner is unset)" description: "Comma or newline-separated list of repositories to install the GitHub App on (defaults to current repository if owner is unset)"
required: false required: false
skip-token-revoke: skip-token-revoke:
description: "If truthy, the token will not be revoked when the current job is complete" description: "If true, the token will not be revoked when the current job is complete"
required: false required: false
default: "false"
# Make GitHub API configurable to support non-GitHub Cloud use cases # Make GitHub API configurable to support non-GitHub Cloud use cases
# see https://github.com/actions/create-github-app-token/issues/77 # see https://github.com/actions/create-github-app-token/issues/77
github-api-url: github-api-url:
+1 -1
View File
@@ -5,7 +5,7 @@
* @param {import("@octokit/request").request} request * @param {import("@octokit/request").request} request
*/ */
export async function post(core, request) { export async function post(core, request) {
const skipTokenRevoke = Boolean(core.getInput("skip-token-revoke")); const skipTokenRevoke = core.getBooleanInput("skip-token-revoke");
if (skipTokenRevoke) { if (skipTokenRevoke) {
core.info("Token revocation was skipped"); core.info("Token revocation was skipped");
+1 -1
View File
@@ -24,7 +24,7 @@ const repositories = core
.map((s) => s.trim()) .map((s) => s.trim())
.filter((x) => x !== ""); .filter((x) => x !== "");
const skipTokenRevoke = Boolean(core.getInput("skip-token-revoke")); const skipTokenRevoke = core.getBooleanInput("skip-token-revoke");
const permissions = getPermissionsFromInputs(process.env); const permissions = getPermissionsFromInputs(process.env);
+1
View File
@@ -8,6 +8,7 @@ export const DEFAULT_ENV = {
// inputs are set as environment variables with the prefix INPUT_ // inputs are set as environment variables with the prefix INPUT_
// https://docs.github.com/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs // https://docs.github.com/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
"INPUT_GITHUB-API-URL": "https://api.github.com", "INPUT_GITHUB-API-URL": "https://api.github.com",
"INPUT_SKIP-TOKEN-REVOKE": "false",
"INPUT_APP-ID": "123456", "INPUT_APP-ID": "123456",
// This key is invalidated. Its from https://github.com/octokit/auth-app.js/issues/465#issuecomment-1564998327. // This key is invalidated. Its from https://github.com/octokit/auth-app.js/issues/465#issuecomment-1564998327.
"INPUT_PRIVATE-KEY": `-----BEGIN RSA PRIVATE KEY----- "INPUT_PRIVATE-KEY": `-----BEGIN RSA PRIVATE KEY-----
@@ -7,6 +7,7 @@ process.env.STATE_token = "secret123";
// inputs are set as environment variables with the prefix INPUT_ // inputs are set as environment variables with the prefix INPUT_
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs // https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
process.env["INPUT_GITHUB-API-URL"] = "https://api.github.com"; process.env["INPUT_GITHUB-API-URL"] = "https://api.github.com";
process.env["INPUT_SKIP-TOKEN-REVOKE"] = "false";
// 1 hour in the future, not expired // 1 hour in the future, not expired
process.env.STATE_expiresAt = new Date( process.env.STATE_expiresAt = new Date(
+4
View File
@@ -7,6 +7,10 @@ process.env.STATE_token = "secret123";
// 1 hour in the past, expired // 1 hour in the past, expired
process.env.STATE_expiresAt = new Date(Date.now() - 1000 * 60 * 60).toISOString(); process.env.STATE_expiresAt = new Date(Date.now() - 1000 * 60 * 60).toISOString();
// inputs are set as environment variables with the prefix INPUT_
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
process.env["INPUT_SKIP-TOKEN-REVOKE"] = "false";
const mockAgent = new MockAgent(); const mockAgent = new MockAgent();
setGlobalDispatcher(mockAgent); setGlobalDispatcher(mockAgent);
+1
View File
@@ -7,6 +7,7 @@ process.env.STATE_token = "secret123";
// inputs are set as environment variables with the prefix INPUT_ // inputs are set as environment variables with the prefix INPUT_
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs // https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
process.env["INPUT_GITHUB-API-URL"] = "https://api.github.com"; process.env["INPUT_GITHUB-API-URL"] = "https://api.github.com";
process.env["INPUT_SKIP-TOKEN-REVOKE"] = "false";
// 1 hour in the future, not expired // 1 hour in the future, not expired
process.env.STATE_expiresAt = new Date(Date.now() + 1000 * 60 * 60).toISOString(); process.env.STATE_expiresAt = new Date(Date.now() + 1000 * 60 * 60).toISOString();
+4
View File
@@ -2,4 +2,8 @@
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions // https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions
delete process.env.STATE_token; delete process.env.STATE_token;
// inputs are set as environment variables with the prefix INPUT_
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
process.env["INPUT_SKIP-TOKEN-REVOKE"] = "false";
await import("../post.js"); await import("../post.js");