0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.js の脆弱性 CVE-2024-56332 への対応

Posted at

はじめに

Next.js のあるバージョン (>= 13.0.0 < 14.2.21, >= 15.0.0 < 15.1.1) にて影響のある脆弱性が見つかったようです。
以下のリンクは、Next.js の GitHub リポジトリの Security にある、CVE-2024-56332 の脆弱性についてのページへ遷移するリンクです。

ポートフォリオサイトで dependabot のアラートがあったので、自動対応してもらおうとしたら失敗しました。

そこで、手動でバージョンを上げたところ、next のバージョンが 15 以上では swcMinify の設定が削除されたとのことだったので、紹介のためまとめることにしました。

環境

macOS Sequoia 15.1.1

next: 14.2.13 (バージョンアップ前) -> 15.1.4 (バージョンアップ後)

以下、npm list コマンド実行時の出力です。

├── @biomejs/biome@1.9.4
├── @chromatic-com/storybook@3.2.2
├── @newhighsco/storybook-addon-svgr@2.0.38
├── @react-pdf/renderer@4.1.5
├── @storybook/addon-essentials@8.4.6
├── @storybook/addon-interactions@8.4.6
├── @storybook/addon-links@8.4.6
├── @storybook/addon-onboarding@8.4.6
├── @storybook/addon-styling-webpack@1.0.1
├── @storybook/addon-themes@8.4.6
├── @storybook/blocks@8.4.6
├── @storybook/nextjs@8.4.6
├── @storybook/react@8.4.6
├── @storybook/test@8.4.6
├── @svgr/webpack@8.1.0
├── @types/node@20.17.9
├── @types/react-dom@18.3.1
├── @types/react@18.3.12
├── autoprefixer@10.4.20
├── eslint-config-next@14.0.4
├── eslint-plugin-storybook@0.11.1
├── eslint@8.57.1
├── file-loader@6.2.0
├── next@15.1.4
├── postcss@8.4.49
├── prettier-plugin-tailwindcss@0.5.14
├── prettier@3.4.1
├── raw-loader@4.0.2
├── react-dom@18.3.1
├── react-hook-form@7.53.2
├── react-icons@5.3.0
├── react-pdf@9.1.1
├── react@18.3.1
├── storybook@8.4.6
├── tailwindcss-animated@1.1.2
├── tailwindcss@3.4.15
├── tsconfig-paths-webpack-plugin@4.2.0
├── typescript@5.7.2
└── worker-loader@3.0.8

解決方法

Next.js のバージョンを最新バージョンである 15.1.2, 14.2.21, 13.5.8 のいずれかに変更することで解決します。

先に記載した公式 GitHub のリンクでは、以下のように書かれています。
"There are no official workarounds for this vulnerability."
とのことで、公式の回避策がないとのことで、バージョンアップ以外に対応策はなさそうです。

脆弱性 CVE-2024-56332 について

脆弱性の内容については、先のリンクの他に、以下のページに詳しくまとめられています。

まとめると、攻撃者が Server Actions でのリクエストを何度も送ることができ、サービス拒否 (Dos) の攻撃ができてしまうようです。

解決までに行ったこと

基本は next のバージョンを上げるだけでよいです。

npm install next@latest

最新版ではなく、バージョンを指定してインストールしたい場合は、以下のように対応した各バージョンを指定してコマンドを実行しましょう。

npm install next@15.1.2
npm install next@14.2.21
npm install next@13.5.8

基本はこれでいいのですが、開発環境を構築する際に、以下のような警告が出ました。

⚠ Invalid next.config.js options detected:
⚠ Unrecognized key(s) in object: 'swcMinify'
⚠ See more info here: https://nextjs.org/docs/messages/invalid-next-config

これは、next.config.js ファイルに、swcMinify のオプションを設定しているためです。
next のバージョンが 15 以上では、swcMinify の設定項目が削除されています。バージョンの方から探した限り見つからず、swcMinify の項目に書いてあったので、そのページを載せます。Good to know という欄にあります。

私は pdfjs というパッケージを用いようとしており、その際に swcMinify に関する設定をしていました。
警告文の内容と、開発環境は正常に立ち上がるところを見る限り、さほど致命的なものでもなさそうであり、あくまでも警告のようです。

おわりに

コミットメッセージで swcMinify の設定をいつなんのためにしたのかを追えたため、私の場合での設定理由を添えてアップデートに関する記事を簡単にまとめました。

そもそも、next のバージョンが 15 以下でこの脆弱性を解決するバージョンがあるので、そちらに合わせることでもこの警告を回避できそうです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?