Repository navigation
build: harden the npm config with @lavamoat/harden - #140
Merged
Merged
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Draft
This was referenced Nov 10, 2026
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.
Applies @lavamoat/harden 0.8.1 at its
moderatelevel for npm, plusn_nogitfromstrict, and makesnpm run lintfail if any of it gets removed.Added
.npmrcsettings:min-release-age=3(skip versions published in the last 3 days),allow-git=none,git=false,allow-remote=noneandallow-scripts-pin=true.devEnginesinpackage.jsonrequiring npm 11.17 or newer, withonFail: error. Node 24 and 26 bundle npm 11.19.1 and 11.20.0, and CI's test job installs the latest npm, so every CI job meets it. Node 22's npm 10.9.9 now stops withEBADDEVENGINES.allowScriptsinpackage.jsonwith one entry,"fsevents@2.3.3": false. fsevents (macOS only, pulled in by vite through@doc-kit/generator-react) has no install script of its own; npm infersnode-gyp rebuildfrom itsbinding.gyp. The package already ships a prebuiltfsevents.nodethat loads without that step, so the entry records the review and silences npm's "install scripts blocked" warning. No other dependency has an install script, so nothing is allowed to run one.@lavamoat/harden0.8.1 as a pinned dev dependency.tools/harden/decisions.json, the decisions snapshot used to apply this (harden defaults -p npm -l moderate -d tools/harden/decisions.json). It picksallowScriptsover disabling scripts, denies existing install scripts instead of approving them, turns onn_nogit, and turns offn_runner.npm run lint:harden, now part ofnpm run lint.harden checkcan only check one whole level and has no way to skip an opinion, so the script runs it atstrictwith--jsonand pipes the report totools/harden/check.mjs, which fails on every opinion that isn't applied unlessdecisions.jsonturns it off. That leavesn_runneras the only strict opinion it ignores.tools/harden/test/check.test.mjs, anode --testsuite forcheck.mjs: it passes when everything is applied, fails on an unapplied opinion, passes when the only unapplied opinion is onedecisions.jsondeclines, and fails on empty input (what it gets ifhardencrashes).lint:hardenruns it before the check, so the CI lint job runs it too.Changed
npm run lintrunslint:hardenafter docov. The lint job in CI already runs it after a root install.actions/setup-nodestep that installs (ci.yml's lint, types and test jobs, docs.yml and the nightly build) now setspackage-manager-cache: false, like release.yml's pack job already did. setup-node v7 readsdevEngines.packageManager, turns on npm caching, and then fails every job because the repo has no lockfile..npmrcblocks, and mentionslint:harden.Not applied
n_runnerreplaces npm's script shell with a wrapper that filters environment variables, reordersPATHand adds Node permission flags. harden's README says it doesn't work in Windowscmd.exe, so it's left off to keepnpm runworking for anyone developing on Windows.Checks
harden check -p npm -l strictbefore: 1 of 8 opinions (n_gitonly). After: 7 of 8, everything exceptn_runner.-l moderatenow passes.All run locally after deleting every
node_modules:npm install --workspaces --include-workspace-root,npm run lint,npm run types(no diff),npm testandnpm run coverage(182 tests each run, 0 failures, 100% coverage in every package),npm run docs,npm run build -w static, andnpm pack -w core -w static --dry-run.npm install --workspaces=falsethennpm run lint, and the types job's install thennpm run types.npm install -g npminstalls today):npm install -w translate,npm run coverage -w translateandnpm run lint:harden.git=falsefrom.npmrcmakeslint:hardenfail withharden: n_nogit is not applied; removingmin-release-agetoo addsn_age.check.mjstests pass and cover it fully (c8, 100% statements and branches through the spawned process). Ignoringdecisions.jsonincheck.mjsfails the declined-opinion test, and ignoringsatisfiedfails 3 of 4.The release age gate didn't block any dependency, since every install above resolved. Dependabot already waits 7 days before bumping, so its regular PRs clear the 3-day gate. Security updates skip that cooldown, so one for a version under 3 days old would fail to install until it ages; npm's
min-release-age-excludein.npmrccan exempt that one package if it can't wait.