Miggo Logo

CVE-2025-57752: Next.js Affected by Cache Key Confusion for Image Optimization API Routes

6.2

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:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/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 lies in the Next.js Image Optimizer's handling of images served from internal API routes. When these API routes produce different image content based on request headers (e.g., Cookie for session-based access or Authorization for token-based access), the optimizer's cache fails to differentiate between these variations. The root cause was identified in the fetchInternalImage function within packages/next/src/server/image-optimizer.ts. This function was forwarding the incoming request's headers to the internal API route, causing the route to generate a user-specific image. However, the resulting optimized image was stored in the cache using a key that did not include the headers that influenced the image content. Consequently, subsequent requests for the same image URL from different users would receive the cached, potentially sensitive, image. The security patch addresses this by removing the headers: _req.headers, line, thereby preventing the user-specific headers from being passed to the internal API route during the image fetch operation. This ensures that the generated image is generic and safe to be served from the cache to any user.

Vulnerable functions

fetchInternalImage
packages/next/src/server/image-optimizer.ts
The `fetchInternalImage` function was responsible for fetching images from internal API routes for optimization. It forwarded request headers (like `Cookie` or `Authorization`) from the user's request to the internal API route. The Next.js image optimization cache key, however, did not factor in these headers. This discrepancy allowed a cached image generated for an authenticated or specific user to be served to other users who requested the same image URL but had different or no authentication headers, leading to information disclosure.

WAF Protection Rules

WAF Rule

* vuln*r**ility in N*xt.js Im*** Optimiz*tion **s ***n *ix** in v**.*.* *n* v**.*.**. W**n im***s r*turn** *rom *PI rout*s v*ry **s** on r*qu*st *****rs (su** *s `*ooki*` or `*ut*oriz*tion`), t**s* r*spons*s *oul* ** in*orr**tly ****** *n* s*rv** to

Reasoning

T** vuln*r**ility li*s in t** N*xt.js Im*** Optimiz*r's **n*lin* o* im***s s*rv** *rom int*rn*l *PI rout*s. W**n t**s* *PI rout*s pro*u** *i***r*nt im*** *ont*nt **s** on r*qu*st *****rs (*.*., `*ooki*` *or s*ssion-**s** ****ss or `*ut*oriz*tion` *or