Thank You Next Part 2: Finding an Order-of-Operations Bypass to the Most Vexing Bugfix Ever
"Look what I found." (Hint: It's not love.)
You know how some vendors like to hide security fixes? Well, it seems Next.js has come up with an entirely new way of hiding security issues! If there was ever a Nobel Prize for (Inadvertently?) Hiding Security Issues, my vote would go to Next.js, then maybe Fortinet.1
Last episode on the Thank You Next fever dream, I showcased multiple DOM-Based XSS vulnerabilities affecting 11 Next.js applications, ranging from AI workflow apps to self-hosted productivity apps. The flaw comes when untrusted input is passed into router.push and router.replace. But! (intense music intensifies!)
In versions 16.2.0 onward, Next.js introduced additional checks to its Router implementation. The unsaid expectation is that JavaScript URLs entering Next Router should no longer work, meaning we can mourn the death of router.push and router.replace as XSS sinks. (Curses!)
First: JavaScript URL XSS triggers successfully in Next.js 16.1.7. Second: Same payload does not work in and after Next.js 16.2.0. With the new protections, a JavaScript URL entering Next Router will be blocked. “Next.js has blocked a javascript: URL as a security precaution.”
But wait!
All hope is not lost!
For in this second post, I shall demonstrate a bypass of these protections for Pages Router. A bypass which they rejected after various attempts at communication. A bypass which they have demonstrated is not worth their time.
Disclaimer
Upon discovery, the finding was reported via standard means to Vercel’s HackerOne Bug Bounty program, as instructed by Next.js’ vulnerability disclosure procedures. Triage rejected the issue. See timeline for more details.
The Sitch
JavaScript URLs are special types of URLs. When a browser navigates to such an URL, the JavaScript code within is executed. This makes them a ripe, commonly overlooked vector for XSS.
What happens when a JavaScript URL reaches window.location?
Under the hood, router.push and router.replace can trigger XSS because they pass URLs to window.location.
With that context out of the way, let’s talk about this Most Vexing Bugfix. PR#88185 introduces a validation function isJavaScriptURLString, called multiple times across the codebase to guard against… well… JavaScript URLs. The validator uses a regex inspired by React’s JavaScript URL sanitiser, which tightly follows the WHATWG spec.
packages/next/src/client/lib/javascript-url.ts
Right off the bat, we can think of several ways where this guard may fail:
- Could the regex be misaligned with the spec?
- Could a browser implementation be misaligned with the spec? Does the browser perform normalisation on JavaScript URLs? Does it support additional control characters?
Those are fun challenges to toy around with! (And potential room for further research!) However, the bypass in the post uses neither approach.
Before we move on, I should clarify that there are two kinds of Routers in Next.js: the Pages Router and the App Router. In JS frameworks, a router is a system which maps URLs to the appropriate file or function. For instance, a Next.js application with the URL http://localhost:3000/user/1/profile could map to a file app/user/[id]/profile/page.tsx. Thus, it makes sense that if the URL is external, then the router should perform an external redirect.
The specific implementation details of each router doesn’t really matter here. The point is: Next.js applications will only pick one router implementation.2
Now, let’s move on to the technical deets!
Exploration
How does the Pages Router handle external redirects? Where is the real DOM-XSS sink?
We know that untrusted data passed into router.push/replace is subsequently passed to a DOM-XSS sink… but what happens in between?
There are several approaches to answer these questions. We could do a static analysis by reading the code, grepping for common DOM-XSS sinks, and trying to trace them back.
But we can also approach this with dynamic analysis by hooking common sinks. And this is also a fun exercise to put tools into practice!
I’ll be using DOM Invader, partly because of convenience being a tool offered by Burp Suite, and partly because I wanted to learn it.
Anyhow, let's start with some setup!
(0) Open Burp's integrated Chromium browser, and click on the Burp extension. (1) Enable DOM Invader. (2) Select Misc. (3) Enable redirect prevention, so that if we try a https:// redirect payload, the page doesn't proceed with the redirect. (4) Reload.
Earlier I mentioned the sink was window.location. But what if we don't know what the sink is? Since it could be anything, let's go ahead and enable all the sinks! There might be some false-positives, and not all of these sinks result in DOM XSS, but we can filter through those manually later.
I'll be using a custom login page.
auth.tsx
We're almost ready! All that's left is to copy the canary and put it into the attacker-controlled "source". The canary is used to detect whether a payload reaches a sink. For a reflected DOM-based XSS, like in this example, the canary would be placed in URL query parameters. The specific payload I chose was redirect=http://example.com/{canary}, which is an external URL.3
Let's try to login!
(1-3) Login. (4) A new sink popped up! (5-6) View the stack trace.
When our canary payload reaches a suitable sink, DOM Invader will record it, along with a beautiful stack trace. Notice how the stack trace shows Router.push, followed by Router.change and handleHardNavigation (most recent call = higher on the stack trace).
Clicking on the links in the stack trace leads us to the concrete sink, which happens to be window.location.href = url.
We have now answered one of our questions and confirmed the exact DOM XSS sink. Technically, we don't need to know the exact sink to find the bypass, but it is useful to gain visibility and reason about the taint path holistically.
Taint Path (Pages Router router.push to window.location):
Next, let's explore what happens between router.push and the window.location sink.
In Pages Router, router.push and router.replace now handle external URLs like so:
- check if the URL starts with a JavaScript URL pattern (
isJavaScriptURLString), - strip the origin from the start of the string (
prepareUrlAs,stripOrigin), - handle the redirect (
window.location).
Do you see the problem?
Exploiting the Flaw
That’s right, not only did Next.js successfully come up with a new way of hiding security issues, but somewhere along the way, they somehow managed to introduce an obscure order-of-operations flaw.4 To be clear, this flaw is not entirely new, but it has only been made useful now, when weaponised as a bypass.
The key to exploitation lies in prepareUrlAs. Its downfall comes down to its reliance on simple string operations such as .startsWith and .substring. And this can be easily bypassed by simply prepending the origin. For example, if the site has an origin http://localhost:3000, then the payload would be http://localhost:3000javascript:alert(1).
Here are the relevant functions. Notice how http://localhost:3000javascript:alert(1) turns into javascript:alert(1).
Note that to exploit this practically, the attacker needs to first know the target site’s origin. To my knowledge, it is not possible to exploit with a universal payload.
Remediation
So what is the solution?
Instead of guarding before stripping, the code should first strip, then guard, and finally execute the navigation.
A good rule of thumb is that the guard should live as close to the sink as possible.
Is App Router affected?
App Router is not affected. It uses URL parsing, which is considerably more rigid compared to toying around with raw string shenanigans. Specifically, it uses JavaScript’s built-in URL class.
Analysing the App Router is left as an exercise for the reader.
What’s next?
There are still a lot of things we haven’t covered in these two technical posts!
How does Next.js qualify for the Nobel Prize for Hiding Security Issues? What is this most vexing bugfix you speaketh of? Does the Router XSS sink still exist? How do we navigate disclosure today?
Fret not. We’ll sail through these murky waters in the next post.
I will say this again: this situation is such a fever dream of a security disclosure, because not only do you have to deal with the usual coordination woes, but there are also issues of transparency and responsibility which— if left undiscussed— are potential landmines for devs and hackers alike.
Stay tuned for the next post!
Appendix
What AI model did you use?
I used the limited model HMN-LLM v13017295. Access to this premium model is available at 1 USD per I/O token. It features 2B parameters, a live mukbang mode, with k-dimensional pressure-sensed temperature settings. You can find a demo here: hmnai.
High-Level Timeline
- 2023.01.20 - Documented evidence shows that the first disclosure to Next.js regarding the XSS issue was made on this day.
- 2023.05.20 - A GitHub issue was posted by hamid-bhz sharing the XSS. A maintainer replied with a won't fix. This is the first publicly documented report which sets a precedent. The implications are that fixes (and therefore advisories) need to be handled on the application-level rather than the package-level.
- 2024.04.12 - A blog post was published by Mobin Yardim on Medium sharing the XSS. The post documents the author's exchange with Next.js and how the vulnerability was first reported in Jan 20, 2023.
- 2026.01.08 - PR#88185 was merged to canary— Next.js' development branch.
- 2026.03.19 - The commit from PR#88185 was released in Next.js 16.2.0, but not backported to 16.1.7 even though other security fixes were. No advisory or CVE was issued.
Disclosure Timeline
- 2026.02 - I discovered an XSS issue during a penetration test. After tracing the root cause, I determined it was due to unsanitised data passed to Next router. This was my first encounter of the pattern.
- 2026.03.07 - I discovered the same pattern in other Next.js applications and was able to reproduce XSS. Due to the precedent from 2023 and without knowledge of PR#88185, I privately reported the issue individually to each app. Specific disclosure timelines for each application can be found in the advisories linked in the first post.
- 2026.03.12 - I discovered the existence of PR#88185, which at this moment has been merged but yet to be released.
- 2026.03.15 - Pursued an attempt at discussion via Vercel's HackerOne program (report 3601037). The report was closed on the same day for the following reason: "After reviewing your submission, this report is being closed as it does not constitute a vulnerability report."
- 2026.03.15 - Pursued an attempt at discussion via direct email to four (4) Next.js maintainers. No response.
- 2026.03.19 - The commit from PR#88185 was released in Next.js 16.2.0, but not backported to 16.1.7 even though other security fixes were. No advisory or CVE was issued.
- 2026.03.20 - Opened a second HackerOne report 3618381 in an attempt to clarify my position.
- 2026.03.29 - Sent a direct email to one (1) Next.js maintainer in an attempt to initiate discussion. This maintainer was not contacted previously. No response.
- 2026.04.03 - Sent a follow-up email to the recent Next.js maintainer. No response.
- 2026.04.19 - Discussion with HackerOne triage ensues. However, triage consistently (stubbornly?) cites points such as:
- It's a developer misuse issue, so it's out-of-scope. "The Next.js router functions operate as designed, and the framework does not explicitly sanitize user input passed to router.push or router.replace because these APIs expect developers to validate input at the application layer."
- It's a "defense in depth".
- Discussion for the second HackerOne report continues until May 22, 2026.
- 2026.04.21 - I opened a third HackerOne report 3687674. This is a completely new finding which partially bypasses PR#88185.
- 2026.05.31 - Triage responds to the third report, and continue to cite the previous stance. Discussion for the third HackerOne report continues until June 2, 2026.
- 2026.07.05 - Posted open letter on GitHub Discussions.
- 2026.07.06 - Sent a follow-up email to the five (5) previously contacted maintainers, attaching a link to the GitHub Discussion. No response.
Footnotes
And just going throw this out there: I'm not really a fan of Ariana Grande (or any pop music in particular), but the opportunity for a punny title is just too good to pass. :) ↩︎
Hint: You can tell which router is used based on the imports. Pages Router uses
import x from 'next/router'whereas App Router usesimport x from 'next/navigation'. ↩︎You can also try
redirect=http://{canary}.com, which should work. You could also tryredirect={canary}, but you'll notice the results are different. (Think: why?) ↩︎Some might even call this a backdoor— audible gasp!— but Hanlon’s razor. ↩︎
Comments are back! Privacy-focused; without ads, bloatware 🤮, and trackers. Be one of the first to contribute to the discussion— before AI invades social media, world leaders declare war on guppies, and what little humanity left is lost to time.











