Security: NPM_TOKEN written to .npmrc file without restricted permissions - #1214
Open
tomaioo wants to merge 1 commit into
Open
Conversation
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>
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.
Summary
Security: NPM_TOKEN written to .npmrc file without restricted permissions
Problem
Severity:
Medium| File:lib/set-npmrc-auth.js:L36In
lib/set-npmrc-auth.js, theNPM_TOKENenvironment variable is written to a temporary.npmrcfile usingfs.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
.npmrcfile to ensure only the owner can read it. You can achieve this by writing the file withfs.writeFileand then usingfs.chmod, or by using a library that supports permission modes.Changes
lib/set-npmrc-auth.js(modified)