CheatSheetSeries icon indicating copy to clipboard operation
CheatSheetSeries copied to clipboard

Update: NPM_Security_Cheat_Sheet - checking a project you did not write before the first install

Open cryptostrapon opened this issue 1 month ago • 5 comments

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 scripts in package.json before installing, and install with --ignore-scripts first.
  • Check the project's .npmrc (and .yarnrc / .yarnrc.yml) for registry and auth token lines.
  • Check dependencies for git, URL, file: and link: 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.

cryptostrapon avatar Nov 05 '26 20:11 cryptostrapon

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.json scripts and installing with --ignore-scripts first
  • Checking project .npmrc and .yarnrc files for registry overrides and auth tokens
  • Flagging git, URL, file: and link: 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.

RahilSahu avatar Nov 05 '26 23:11 RahilSahu

@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!

mackowski avatar Nov 06 '26 10:11 mackowski

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.

RahilSahu avatar Nov 06 '26 10:11 RahilSahu

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 avatar Nov 06 '26 12:11 randomstuff

@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.

cryptostrapon avatar Nov 06 '26 23:11 cryptostrapon