CVE-2021-39178: XSS in Image Optimization API for Next.js

next Updated 02 Oct 2025

Summary

01/09/2021
Yes i
High
7.5

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 ↓

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

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 →

Share this vulnerability

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.

Related vulnerabilities

Recent vulnerabilities recorded for next.

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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback