Zero Click Mass Account Takeover on Exchange
A Next.js caching flaw allowed an attacker to poison the cache for the login page with a malicious JSON response containing a script in the pageProps, which then executed as HTML for any visitor. Because session cookies lacked security flags, this led to mass account takeover.
medium.com
Published on medium.com
Hey everyone, I’m Erfan (Maverick). In this write-up, I’m going to show you how I discovered a vulnerability that I’ve named “Zero Click Mass Account Takeover.” It has both technical and non-technical sides, so I’ve split it into two parts.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, Next.js treated requests with a special header as static and cacheable, and the application reflected user-controlled input (the theme cookie) into page data without sanitisation, allowing cache poisoning with script content.
Impact
Any user visiting the login page could have their session cookies stolen, leading to account takeover, as the cookies lacked security flags.
What the attacker needed
Target uses Next.js; attacker can send requests with custom headers; victim visits the login page
How it was found
- Send a request to the login path with the __nextDataReq parameter to receive JSON data including pageProps.
- Add the x-now-route-matches header and send the request multiple times to make Next.js cache the response.
- Inject a script payload into the theme cookie so it appears in pageProps.
- Visit the login page without the parameter to have the cached JSON served as HTML, executing the script.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The website used a framework called Next.js, which can serve pages either as full web pages or as raw data. The attacker tricked the server into storing a data response that contained a malicious script, and then made the server hand that stored response to everyone who visited the login page. Since the script ran in visitors' browsers and their login cookies were not protected, the attacker could steal their sessions and take over their accounts.
What is Cache bugs?
A cache and the origin disagree about a request, so a poisoned response is served to everyone or a private page is stored as public.