CVE-2021-39178: XSS in Image Optimization API for Next.js
Summary
CVE-2021-39178: XSS in Image Optimization API for Next.js. Affects next versions >= 10.0.0, < 11.1.1. Fixed in 11.1.1. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Next.js is a popular open-source framework for building server-side rendered (SSR) and static websites using React. It provides features like automatic code splitting, server-side rendering, and optimized image loading. The Image Optimization API in Next.js allows developers to optimize and serve images in their applications. However, a vulnerability in Next.js versions 10.0.0 to 11.1.0 allows for cross-site scripting (XSS) attacks when user-provided SVG images are allowed by the image host specified in the next.config.js file.
Vulnerability Detail
The XSS vulnerability in Next.js can be exploited when the following conditions are met: Next.js version is between 10.0.0 and 11.1.0, the next.config.js file has the images.domains array assigned, and the image host specified in images.domains allows user-provided SVG images. An attacker can craft a malicious SVG image that contains JavaScript code, which will be executed in the context of the vulnerable application when the image is rendered. This can lead to various security risks, including unauthorized access, data theft, and session hijacking. Deployments on Vercel are not affected, and the vulnerability can be mitigated by upgrading to Next.js version 11.1.1.
How To Fix
Latest published version: 16.4.2 as of 22 Oct 2026
npm install next@16.4.2
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
11.1.1
This is the first release that contains the fix.
npm install next@11.1.1
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Conclusion
The XSS vulnerability in Next.js versions 10.0.0 to 11.1.0 can lead to cross-site scripting attacks when user-provided SVG images are allowed by the image host. It is crucial for developers to upgrade to Next.js version 11.1.1 or later to mitigate this vulnerability. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for next →
FAQ
Next.js is an open-source framework for building server-side rendered (SSR) and static websites using React. It provides features like automatic code splitting, server-side rendering, and optimized image loading.
The vulnerability allows for cross-site scripting (XSS) attacks when user-provided SVG images are allowed by the image host specified in the next.config.js file. This can lead to various security risks, including unauthorized access, data theft, and session hijacking.
You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. Simply provide your package-lock.json file, and Vulert will analyze it in real-time.
No, deployments on Vercel are not affected by this vulnerability.
No, there is no known workaround for this vulnerability. It is recommended to upgrade to Next.js version 11.1.1 or later.
References
Related vulnerabilities
Recent vulnerabilities recorded for next.