Yarn Rules
YRN001: yarn npmMinimalAgeGate is below 7 days
Severity: high
Yarn berry 4.10+ supports npmMinimalAgeGate (in minutes, or as a duration string like "7d"), which delays installation of freshly published packages. A value of at least 7 days mitigates supply-chain attacks via fast-yanked malicious releases. Yarn classic (1.x) does not support this setting and is skipped.
What it checks:
- Whether
yarnis onPATH(skipped if not installed) - Whether
yarn --versionreports2.x+(yarn 1.x is skipped) - Whether
yarn config get npmMinimalAgeGateresolves to>= 7days (numeric values are interpreted as minutes; duration strings are parsed via the shared duration helper)
Remediation:
# ~/.yarnrc.yml
npmMinimalAgeGate: 10080# or
yarn config set --home npmMinimalAgeGate 10080YRN002: yarn install scripts are not disabled
Severity: high
Yarn berry runs lifecycle scripts (preinstall, install, postinstall) declared by dependencies during install. Setting enableScripts: false in the user/global .yarnrc.yml disables this behaviour, removing the primary execution vector used by compromised npm packages. Yarn classic (1.x) lacks an equivalent global toggle and is skipped.
What it checks:
- Whether
yarnis onPATH(skipped if not installed) - Whether
yarn --versionreports2.x+(yarn 1.x is skipped) - Whether
yarn config get enableScriptsreturnsfalse
Remediation:
yarn config set --home enableScripts false# ~/.yarnrc.yml
enableScripts: falseNote: with enableScripts: false, packages that need a native build (esbuild, sharp, node-gyp users) must be allow-listed via npmPreapprovedPackages in .yarnrc.yml.
YRN003: yarn auth token stored in plaintext in .yarnrc.yml
Severity: critical
Yarn berry stores npmAuthToken and npmAuthIdent either at the top level of ~/.yarnrc.yml or nested under npmRegistries: / npmScopes: blocks. Literal values left on disk are recoverable by any process that can read the file — malware, compromised dependencies, sync clients, or backups. Env-var references such as ${NPM_TOKEN} are accepted as safe indirection and pass. Yarn classic (1.x) does not use this file format and is skipped.
What it checks:
- Whether
yarnis onPATH(skipped if not installed) - Whether
yarn --versionreports2.x+(yarn 1.x is skipped) - Reads
~/.yarnrc.ymlif it exists - Flags any literal (non-empty, non-env-var) value assigned to
npmAuthTokenornpmAuthIdent, at any indentation level
Remediation:
# ~/.yarnrc.yml — env-var indirection, safe
npmAuthToken: "${NPM_TOKEN}"Inject NPM_TOKEN from a keychain, password manager, or CI secret store at session start. Rotate any token that has been on disk.
