Next.js Vulnerabilities Expose Websites to Cache Poisoning and XSS Attacks
2025-01-24
Want to show the importance of securing popular frameworks and the risks of improper caching? This article on Next.js vulnerabilities is a must-read!
Recent research has identified critical vulnerabilities in the Next.js framework, specifically between versions 13.5.1 and 14.2.9, which expose websites to cache poisoning and stored cross-site scripting (XSS) attacks. These vulnerabilities stem from improper caching mechanisms, allowing attackers to manipulate data-fetching routes and request details, resulting in corrupted content delivery and execution of malicious scripts. The issues affect static-route deployments on non-Vercel-hosted sites, necessitating an upgrade to version 14.2.10 or later. Organizations using Next.js must apply patches promptly, modify cache keys, and review their code to safeguard against these threats, given the framework's extensive use and potential impact on user privacy and service availability.
Misconfiguration, Web App/Website Vulnerability, Open Source
Next.js, Cache Poisoning, Stored XSS, CVE-2024-46982, JavaScript Vulnerability, Web Security
Next.js
Recent research has uncovered significant vulnerabilities in the Next.js framework, a widely used JavaScript platform. These vulnerabilities, affecting versions 13.5.1 to 14.2.9, involve cache poisoning and stored cross-site scripting (XSS) attacks. This discovery has prompted crucial discussions in the cybersecurity community about securing Next.js deployments. The vulnerabilities arise from improper caching mechanisms within Next.js, particularly affecting data-fetching routes and the use of Cache poisoning allows attackers to manipulate server-side caches by appending specific parameters and headers to requests. For instance, parameters like Example of Cache Poisoning: Stored XSS is a severe vulnerability where malicious scripts are stored on the server and later executed in users' browsers. In Next.js, an attacker can inject harmful payloads into cached content by exploiting how user-provided data (e.g., Stored XSS Attack Vector: A malicious payload can be served with a Example Payload: One identified vulnerability, CVE-2024-46982, shows how attackers can exploit caching directives like These vulnerabilities impact static-route deployments using the Pages Router on non-Vercel-hosted sites. It is essential to upgrade to Next.js version 14.2.10 or later. Security measures include: With over 6 million weekly downloads, Next.js's popularity means these vulnerabilities could significantly impact availability and user privacy on sensitive platforms. Although Vercel has released patches and advisories, organizations using Next.js must prioritize applying these updates and securing their implementations to protect against advanced exploitation techniques.Critical Vulnerabilities in Next.js Framework: Cache Poisoning and XSS Attacks
Understanding the Vulnerabilities
getStaticProps (SSG) and getServerSideProps (SSR). These functions can be manipulated by attackers when caching misconfigurations occur, leading to cache poisoning and stored XSS attacks.Cache Poisoning Explained
__nextDataReq and headers such as x-now-route-matches can trick the framework into caching dynamic SSR data as static SSG data. This results in restricted content being cached with long expiration times, causing users to receive corrupted content.
/poc returns valid HTML.__nextDataReq, the server might deliver a JSON object instead.Stored XSS via Cache Poisoning
User-Agent, cookies, headers) is reflected using getServerSideProps.text/html content type, executing whenever users access the affected page without further interaction.GET /poc?__nextDataReq=1 HTTP/1.1
User-Agent: CP TO SXSS ON NEXT.JS : <img src=x onerror=alert('Exploit')>
x-now-route-matches: 1CVE-2024-46982 and Cache Misclassification
s-maxage and stale-while-revalidate. By tricking the framework into treating SSR requests as SSG requests, attackers can bypass no-cache controls, leading to private data being cached and reused, risking confidentiality.Affected Deployments and Remediation Steps
getServerSideProps implementations to prevent improper data reflection or caching.Broader Implications
https://cyberpress.org/critical-vulnerability-in-next-js-framework-exposes-websites/?amp=1