Skip to content

Security: NPM_TOKEN written to .npmrc file without restricted permissions - #1214

Open
tomaioo wants to merge 1 commit into
semantic-release:masterfrom
tomaioo:fix/security/npm-token-written-to-npmrc-file-without-
Open

Security: NPM_TOKEN written to .npmrc file without restricted permissions#1214
tomaioo wants to merge 1 commit into
semantic-release:masterfrom
tomaioo:fix/security/npm-token-written-to-npmrc-file-without-

Conversation

@tomaioo

@tomaioo tomaioo commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Security: NPM_TOKEN written to .npmrc file without restricted permissions

Problem

Severity: Medium | File: lib/set-npmrc-auth.js:L36

In lib/set-npmrc-auth.js, the NPM_TOKEN environment variable is written to a temporary .npmrc file using fs.outputFile. This function creates files with default permissions (typically 0644), meaning the file is world-readable. If the CI environment is shared or another user/process can read the temporary directory, the npm authentication token could be exposed.

Solution

Set restrictive file permissions (e.g., 0600) when writing the .npmrc file to ensure only the owner can read it. You can achieve this by writing the file with fs.writeFile and then using fs.chmod, or by using a library that supports permission modes.

Changes

  • lib/set-npmrc-auth.js (modified)

In `lib/set-npmrc-auth.js`, the `NPM_TOKEN` environment variable is written to a temporary `.npmrc` file using `fs.outputFile`. This function creates files with default permissions (typically 0644), meaning the file is world-readable. If the CI environment is shared or another user/process can read the temporary directory, the npm authentication token could be exposed.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant