Node.js xlsxモジュールでhigh severity vulnerability

こんにちは、フリーランスエンジニアの太田雅昭です。

xlsxの脆弱性

strapiにexcelでのインポート機能を実装しようと以下を実行しました。

npm install xlsx

すると以下のメッセージが。

1 high severity vulnerability

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

言われたコマンドを実行すると

npm audit
# npm audit report

xlsx  *
Severity: high
Prototype Pollution in sheetJS - https://github.com/advisories/GHSA-4r6h-8v6p-xvw6
No fix available
node_modules/xlsx

1 high severity vulnerability

Some issues need review, and may require choosing
a different dependency.

どうやら悪意のあるExcelファイルを読み込んだ時の脆弱性があるようです。high severityとのことですので、これはやばい。

対策

以下に対策が書かれています。

[Security] Prototype Pollution in sheetJS · Issue #2822 · SheetJS/sheetjs

Security] Prototype Pollution in sheetJS GHSA-4r6h-8v6p-xvw6 Affected version: 0.19.3 Description All versions of SheetJS CE through 0.19.2 are vulnerable to “Prototype Pollution” when reading specially crafted files. Workflows that do …

上記によると、脆弱性対応バージョンが存在するものの、メンテナンスされてないため、npm経由ではインストールできないとのこと。

そこで以下のようにします。

npm install https://cdn.sheetjs.com/xlsx-0.19.3/xlsx-0.19.3.tgz

すると以下のようになりました。

found 0 vulnerabilities

いやぁ、よかったよかった。しかしnode.jsでExcelファイルを読み込むのに、メンテナンスされてないモジュールしか選択肢がないのは厳しいですね。一応他にもライブラリはあるようなのですが、どうも調べた感じだと今回の用途には適さないようですので。

2024/02/04追記

現行バージョンは以下になっています。

https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz

公式サイトがあるんですね。

NodeJS | SheetJS Community Edition

Package tarballs are available on .