Skip to content

Commit aaa1a36

Browse files
B4nanclaude
andauthored
fix(pnpm-install): keep github-registry-token off disk (#279)
The token previously landed in ~/.npmrc as plain text, where any later step in the same job could read it — a regression vs the npm pattern this action replaced. Instead, write the literal template '${GITHUB_REGISTRY_TOKEN}' into ~/.npmrc (single quotes, no shell expansion) and inject the env var only for the install step. pnpm expands the template at registry-fetch time; once the install step exits, the env var is gone and ~/.npmrc holds an unusable template — later steps cannot exfiltrate the token. Reported by František on the apify-core pnpm migration review. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6cf59c7 commit aaa1a36

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

pnpm-install/action.yaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ runs:
3838
run_install: false
3939
package_json_file: ${{ inputs.working-directory }}/package.json
4040

41-
# `npm` is always available on the runner via setup-node; using it here
42-
# avoids ordering issues (corepack-managed pnpm isn't on PATH at every
43-
# step) and writes the token into the user-global ~/.npmrc that pnpm
44-
# also reads during install.
41+
# Write a *template* (the literal string `${GITHUB_REGISTRY_TOKEN}`) into
42+
# ~/.npmrc, NOT the expanded token. Using single quotes here is load-
43+
# bearing — they prevent the shell from expanding the variable, so the
44+
# actual token never lands on disk. pnpm/npm expand the template at
45+
# registry-fetch time, reading the env var that we inject only for the
46+
# install step below. Once that step finishes the env var is gone and
47+
# ~/.npmrc holds an unusable template, so later steps in the same job
48+
# cannot exfiltrate the token.
49+
#
50+
# `npm` is always available on the runner via setup-node and is used
51+
# here only because corepack-managed pnpm isn't on PATH at every step.
4552
- name: Configure GitHub npm registry auth
4653
if: inputs.github-registry-token != ''
4754
shell: bash
48-
env:
49-
GITHUB_REGISTRY_TOKEN: ${{ inputs.github-registry-token }}
5055
run: |
51-
npm config set "//npm.pkg.github.com/:_authToken=${GITHUB_REGISTRY_TOKEN}"
56+
npm config set '//npm.pkg.github.com/:_authToken=${GITHUB_REGISTRY_TOKEN}'
5257
5358
- name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
5459
id: pnpm-config
@@ -70,10 +75,14 @@ runs:
7075
restore-keys: |
7176
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
7277
78+
# GITHUB_REGISTRY_TOKEN is exposed only for this step. The .npmrc
79+
# template written above expands it at registry-fetch time, then it's
80+
# gone — no plaintext token ends up on disk for later steps to read.
7381
- name: Install dependencies
7482
shell: bash
7583
working-directory: ${{ inputs.working-directory }}
7684
run: |
7785
pnpm install --frozen-lockfile --prefer-offline --loglevel error
7886
env:
7987
HUSKY: "0"
88+
GITHUB_REGISTRY_TOKEN: ${{ inputs.github-registry-token }}

0 commit comments

Comments
 (0)