Does --ignore-scripts protect you from a take-home repo? Five ways it doesn't
A recruiter you have never met loves your profile, skips the interview and sends a take-home repo the same afternoon. Flattering. Also a classic opening of scams aimed at developers. You know the advice: never run npm in
A recruiter you have never met loves your profile, skips the interview and sends a take-home repo the same afternoon. Flattering. Also a classic opening of scams aimed at developers. You know the advice: never run npm install on a stranger's repo without --ignore-scripts, or put ignore-scripts=true in your ~/.npmrc.
I wanted to know how far that advice goes. So I built a test repo where every trick does one harmless thing: it writes a marker file to /tmp. Then I ran the usual first commands and checked which markers appeared. Four of the five I ran myself (npm 10.9.9 and 12.2.3, Yarn 1.22.22). The dev container one comes from the spec, because it needs Docker on the host.
The setup
Each trick writes its own file, for example:
// marker.js
require('fs').writeFileSync('/tmp/marker-' + process.argv[2], 'ran');
Clean /tmp before each run, run one command, list /tmp/marker-*.
1. The repo's .npmrc beats yours
Your ~/.npmrc has ignore-scripts=true. The repo ships one line:
# ./take-home/.npmrc
ignore-scripts=false
npm reads the project .npmrc after your user file, so the project value wins. npm install runs the postinstall hook. Marker appears.
2. A .npmrc in a workspace folder does nothing
The opposite mistake. In a monorepo you put ignore-scripts=true next to the package you don't trust, in packages/a/.npmrc.
npm only reads the .npmrc at the workspace root. A root npm install prints no warning and runs the postinstall of packages/a. Marker appears. Only when you run a command from inside packages/a does npm log ignoring workspace config at .../packages/a/.npmrc. Tested on npm 10.9.9 and 12.2.3.
3. npm 12 extension files run on npm pack
npm 12 loads .npm-extension.mjs or .npm-extension.cjs from the project. npm pack --ignore-scripts still loads it. Marker appears. Lifecycle scripts are off, project code still runs.
4. yarnPath swaps the yarn binary
# .yarnrc.yml
yarnPath: .yarn/releases/yarn-4.0.0.cjs
Your global yarn hands every command in that folder to the file at yarnPath. I put a marker script at that path and ran yarn --version with Yarn 1.22.22. The marker appeared and the "version" printed was whatever the script chose to print. No install needed.
5. initializeCommand runs on your machine
// .devcontainer/devcontainer.json
{ "initializeCommand": "node marker.js devcontainer" }
People open a suspicious repo in a dev container to stay isolated. The Dev Container spec says initializeCommand runs on the host, before the container is created. Click "Reopen in Container" and the command runs on your own machine.
Results
| Trick | First command | --ignore-scripts helps? |
|---|---|---|
| Repo .npmrc sets ignore-scripts=false | npm install | Yes, if you pass the flag on the command line |
| ignore-scripts=true in a workspace .npmrc | npm install at the root | No, the file is ignored |
| .npm-extension.mjs | npm pack | No |
| yarnPath in .yarnrc.yml | any yarn command | No |
| initializeCommand | Reopen in Container | No |
What I do now before the first command
- Pass
--ignore-scriptson the command line. A command line flag beats every.npmrc. - Open every
.npmrc,.yarnrc.yml,.pnpmfile.cjs,.npm-extension.*anddevcontainer.jsonin the repo, not only the root ones. - Run
npm config lsinside the folder. It shows the effective values and where each one comes from, without running scripts. - Do all of it in a throwaway VM with no SSH keys, cloud credentials or wallets.
To check the files in one step, npm-install-audit reads a repo without running anything and flags all five. A clean result means none of the known tricks showed up, nothing more.
Have you received a take-home repo that shipped its own config files? What was in them?
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.