Miggo Logo

CVE-2025-55173: Next.js Content Injection Vulnerability for Image Optimization

4.3

CVSS Score
3.1

Basic Information

EPSS Score
-
Published
8/29/2025
Updated
8/29/2025
KEV Status
No
Technology
TechnologyJavaScript

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N
Package NameEcosystemVulnerable VersionsFirst Patched Version
nextnpm< 14.2.3114.2.31
nextnpm>= 15.0.0, <= 15.4.415.4.5

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability analysis began by examining the provided patch in commit 6b12c60c61ee80cb0443ccd20de82ca9b4422ddd. The patch clearly shows the removal of headers: _req.headers, from the fetchInternalImage function in packages/next/src/server/image-optimizer.ts. This is a strong indicator that the vulnerability lies in the forwarding of user-controlled headers to an internal service.

The commit message, "The headers were forwarded to the serverless function for "internal" images but not "external" images," corroborates this finding. It explicitly states that headers were being passed along for internal image requests. The added test case further confirms this by asserting that a cookie header is not forwarded to an internal API route after the fix.

While the vulnerability description mentions "attacker-controlled external image sources," the tangible evidence from the code change points directly to a flaw in the handling of internal image sources. The exploit scenario involves the image optimizer being used to make a request to an internal endpoint (like an API route). By forwarding headers, the optimizer allows an attacker to control the input to this internal endpoint, potentially leading to the generation of a malicious response containing a Content-Disposition header.

The root cause is the improper validation and sanitization of headers before they are passed to the internal request. The identified vulnerable function, fetchInternalImage, is the exact location where this unsafe header forwarding occurred. The fix prevents this by no longer passing the headers to the mocked request, thus mitigating the content injection vector.

Vulnerable functions

fetchInternalImage
packages/next/src/server/image-optimizer.ts
The `fetchInternalImage` function was vulnerable because it forwarded all request headers from the incoming request (`_req.headers`) to the internal resource being fetched. If an attacker could specify an internal API route as the image URL, they could send crafted headers to that route. If the API route was vulnerable to header injection or had behavior dependent on headers, an attacker could manipulate the response. This could be used to inject a `Content-Disposition` header, forcing a file download with arbitrary content and filename, leading to phishing or other attacks.

WAF Protection Rules

WAF Rule

* vuln*r**ility in **N*xt.js Im*** Optimiz*tion** **s ***n *ix** in **v**.*.*** *n* **v**.*.****. T** issu* *llow** *tt**k*r-*ontroll** *xt*rn*l im*** sour**s to tri***r *il* *ownlo**s wit* *r*itr*ry *ont*nt *n* *il*n*m*s un**r sp**i*i* *on*i*ur*tion

Reasoning

T** vuln*r**ility *n*lysis ****n *y *x*minin* t** provi*** p*t** in *ommit `****************************************`. T** p*t** *l**rly s*ows t** r*mov*l o* `*****rs: _r*q.*****rs,` *rom t** `**t**Int*rn*lIm***` *un*tion in `p**k***s/n*xt/sr*/s*rv*r