Update: NPM_Security_Cheat_Sheet - checking a project you did not write before the first install
What is missing or needs to be updated?
Section 3 covers lifecycle scripts in third-party packages you add to your own project. It does not cover a case that has become common: someone hands you a whole project, often a recruiter's take-home test, and asks you to run npm install in it.
The FBI IC3 PSA of 3 September 2024 lists "requests to conduct a 'pre-employment test' or debugging exercise that involves executing non-standard or unknown Node.js packages ... or GitHub repositories" as an indicator of these campaigns. Unit 42 described the same pattern in November 2023.
In that case the risky parts sit in the project itself. --ignore-scripts helps only if you remember it before the first install, and some of the risk is not in scripts at all: a project .npmrc that points to another registry or carries an auth token, and dependencies given as git URLs, tarball URLs or file: paths that skip the registry.
How should this be resolved?
Add a short subsection to section 3, for example "Inspecting a project you did not write", with a checklist:
- Read the
scriptsinpackage.jsonbefore installing, and install with--ignore-scriptsfirst. - Check the project's
.npmrc(and.yarnrc/.yarnrc.yml) forregistryand auth token lines. - Check dependencies for git, URL,
file:andlink:specs. - Open the folder in VS Code Restricted Mode, so workspace tasks do not run on open.
- Run it in a disposable container or VM with no credentials or wallets on it.
Sources: the IC3 PSA and Unit 42 report above, and the npm docs on scripts.
Disclosure: we maintain a small open source CLI that automates these checks, npm-install-audit. The checklist stands on its own, so we are happy to leave the tool out if tool links are not wanted.
This proposal was drafted with help from an AI assistant and reviewed before posting.
If this looks useful, we can send a PR for that single file.
Hi, I would like to work on this.
I am a penetration tester and application security engineer, and this scenario comes up in my world too: candidates and engineers are routinely asked to clone and run unknown projects. I will add the "Inspecting a project you did not write" subsection to Section 3 of the NPM Security Cheat Sheet, covering:
- Reading
package.jsonscripts and installing with--ignore-scriptsfirst - Checking project
.npmrcand.yarnrcfiles for registry overrides and auth tokens - Flagging git, URL,
file:andlink:dependency specs that bypass the registry - Opening the project in VS Code Restricted Mode
- Running it in a disposable container or VM with no credentials present
I will cite the FBI IC3 PSA (3 September 2024) and the Unit 42 report linked in the issue, plus the npm docs on scripts and config, and follow the cheat sheet style and the contributor guide. Happy to adjust scope if the maintainers want the subsection shorter or placed elsewhere.
@cryptostrapon thanks for the offer to work on this. Section 3 covers --ignore-scripts for packages you add yourself, but not checking a whole project you did not write, so a short subsection there would be a useful addition. Please keep the checklist concise and vendor-neutral, and cite the public sources mentioned in the issue.
@RahilSahu if you would be able to review the PR from @cryptostrapon that would be a huge help for us!
Thank you, @mackowski. Happy to review @cryptostrapon's PR when it is ready.
I will check it against the checklist in the issue (scripts review and --ignore-scripts, .npmrc and .yarnrc registry and token lines, git/URL/file:/link: dependency specs, VS Code Restricted Mode, disposable environment), plus the IC3 and Unit 42 citations, and the cheat sheet's concise, vendor-neutral style.
@cryptostrapon feel free to tag me on the PR when you open it.
I think this might tread on dangerous path because it is very easy to give misleading (false sense of security) guidelines on this topic. Verifying that a untrusted NPM package is not malicious is very difficult.
@randomstuff agreed, that risk is real, and #2908 now tries to avoid it. The checklist is framed as a first look rather than a verdict: it says --ignore-scripts only postpones the scripts, that the dependency check only catches the visible cases (typosquatting and a tampered lockfile are much harder to spot), and the last step makes isolation the actual control: a disposable VM, ideally remote, with no credentials and restricted network. If a sentence still reads as "this proves the package is safe", happy to change it.