5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

npmサプライチェーン攻撃対策

5
Posted at

開発環境

  • MacBook Air M1, 2020
  • nvm 0.40.4
  • Node.js v22.22.0
  • npm 11.14.1

npm のバージョン確認

$ npm -v
10.9.4

npm のバージョンを11に上げる

$ npm install -g npm@11
$ npm -v
11.14.1

min-release-age の設定

npm 11 以降では min-release-age により、レジストリに公開されてから指定日数が経っていないパッケージ版は npm install できません。公開直後に仕込まれた悪意ある版を、すぐ入れないための対策です(pnpm の minimumReleaseAge に近い考え方)。

  • 7 … 公開から 7 日未満の版はインストール不可(npm のデフォルトは 3 日のため、より厳しく 7 日にしている)
  • --location=user … ユーザー全体の ~/.npmrc に書き込み、この Mac 上のどのプロジェクトでも常に効かせる

注意: 正当なアップデートも公開直後は 7 日間入れられません。

$ npm config set min-release-age 7 --location=user

確認

$ npm config get min-release-age
7

Takumi Guard の導入

Takumi Guard(GMO Flatt Security)の npm 用プロキシレジストリです。npm install の取得先を https://npm.flatt.tech/ に向けると、公開 npm パッケージを経由で取得し、ブロックリストに載った悪性パッケージなどをインストール前に拒否します。

min-release-age が「公開から一定期間待つ」対策であるのに対し、こちらは「取得経路で弾く」対策です。併用すると二重の防御になります。

$ npm config set registry https://npm.flatt.tech/

確認

$ npm config get registry
https://npm.flatt.tech/
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?