/

CVE-2026-21884

Severity:

HIGH RISK

(8.2)

XSS in React Router <ScrollRestoration> Framework Mode SSR

CVE-2026-21884

Modified

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Client-Side Code Execution / Cross-Site Scripting

Severity:

HIGH RISK

(8.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A cross-site scripting (XSS) issue in React Router's <ScrollRestoration> API can occur during server-side rendering in Framework Mode when getKey or storageKey props are derived from untrusted input.

If an attacker can influence these values, they may be able to trigger arbitrary JavaScript execution in the rendered HTML during SSR, leading to script injection in users' browsers.

Affected context

This vulnerability affects applications that:

  • Use React Router or @remix-run/react in Framework Mode with server-side rendering enabled, and
  • Use the <ScrollRestoration> component with getKey and/or storageKey props, and
  • Allow untrusted or user-controlled data to influence the scroll restoration keys.

Applications using Declarative Mode (<BrowserRouter>) or Data Mode (createBrowserRouter / <RouterProvider>), or that have Framework Mode SSR disabled, are generally not affected by this specific behavior.

Exploit preconditions

  • Attack surface: Web application front-end rendered via React Router in Framework Mode SSR.
  • Required access: Ability to control or influence data used to generate the getKey or storageKey values (e.g., via query params, path segments, headers, or persisted data that flows into these props).
  • Trigger point: A server-side render that includes <ScrollRestoration> with keys derived from attacker-influenced data; the SSR output is then delivered to the browser and interpreted as HTML/JavaScript.
  • Why exploitation is possible: The scroll restoration keys are incorporated into the SSR output in a way that can break out of intended encoding and inject script-capable content. Because the keys are not strictly constrained or safely encoded for the context in which they are embedded, attacker-controlled values can result in XSS.

Why this happens

The root cause falls under CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).

In Framework Mode SSR, React Router's <ScrollRestoration> uses getKey/storageKey values to create identifiers used for preserving scroll position. When these keys are derived from untrusted input and embedded in the SSR HTML without sufficient context-aware encoding, they can introduce executable JavaScript into the page.

Conceptually, this is an output encoding problem: values that should behave as inert data (keys) are allowed to influence the structure of the rendered HTML/JavaScript during SSR. This insecure pattern combines:

  • treating attacker-controlled values as trusted,
  • rendering them in a sensitive HTML/JS context,
  • and relying on application code to avoid hazardous characters rather than enforcing strict constraints or automatic escaping.

Potential impact

  • Execution of arbitrary JavaScript in the context of the affected web application.
  • Theft of session tokens, API tokens, or other sensitive information accessible to the browser.
  • Unauthorized actions performed on behalf of authenticated users (e.g., account changes, data manipulation).
  • Defacement of application content or injection of malicious UI elements (phishing overlays, fake dialogs).
  • Use of the site as a delivery vehicle for further client-side exploitation or malware distribution.

General mitigation guidance

Mitigation centers on treating all data that can reach getKey/storageKey as untrusted and ensuring it cannot affect HTML/JS structure:

  • Prefer static or strictly controlled keys for <ScrollRestoration> rather than dynamically building them from raw user input.
  • If dynamic keys are required, ensure they are normalized and constrained (e.g., limited character sets, fixed formats, length restrictions) before they are used in the component.
  • Apply context-aware output encoding where keys may flow into HTML or script contexts within SSR templates, so that they remain inert data and cannot break out into executable code.
  • Architect routes and scroll restoration logic so that identifiers come from trusted application state or server-generated tokens instead of directly from request parameters or unvalidated headers.
  • Adopt a secure-by-default SSR pattern: centralize how values are serialized into the HTML response and enforce escaping/encoding at that boundary rather than in individual components.

These patterns help ensure that even if untrusted data is present in routing or state, it cannot be rendered as executable script by the server.

How teams detect issues like this

Effective detection involves both code-level inspection and automated checks:

  • Static analysis and linters: Configure rules to flag:
  • Uses of <ScrollRestoration> where getKey or storageKey are derived (directly or indirectly) from location, query params, request headers, or other user-controlled inputs.
  • Custom serialization logic that embeds route-related data into inline scripts or data attributes without explicit encoding.
  • Code review heuristics:
  • Trace the data flow for any values passed into getKey/storageKey and verify that they are either constant, server-controlled, or rigorously validated.
  • Look for ad-hoc escaping or manual string concatenation involving routing state in SSR code; treat these as high-risk and require justification.
  • Security testing:
  • Incorporate XSS payload testing into automated SSR integration tests for routes that use <ScrollRestoration> in Framework Mode.
  • Use dynamic scanners or security proxies to attempt injection via parameters known to influence routing and keys.
  • Policy enforcement:
  • Establish project guidelines that any data rendered into SSR output must pass through well-defined serialization/encoding functions.
  • Optionally, integrate SAST/DAST tools into CI to highlight unescaped uses of routing state in server-rendered HTML.

Sources

SourceLink
github.comgithub.com/remix-run/react-router/security/advisories/GHSA-8v8x-cx79-35w7
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19712
access.redhat.comaccess.redhat.com/errata/RHSA-2026:3782
access.redhat.comaccess.redhat.com/errata/RHSA-2026:3958
access.redhat.comaccess.redhat.com/errata/RHSA-2026:3960
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-21884
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2428421
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-21884.json

Frequently asked

questions

Yes. If attacker-controlled input can influence the getKey or storageKey values during SSR in Framework Mode, the attacker can exploit the issue remotely by crafting requests that cause malicious keys to be included in the rendered HTML.

Not necessarily. If the application uses unauthenticated routes where request parameters or headers are used to derive scroll restoration keys, exploitation can be fully unauthenticated. In other deployments, the attacker may need an account or some level of access to control the data that flows into these props.

The safest pattern is to ensure that scroll restoration keys are not derived from untrusted input at all. Use stable, application-defined keys or route metadata and enforce strict normalization if any external data is involved. Additionally, make sure that any values serialized into SSR HTML pass through a central, context-aware encoding layer.

Treat any data that crosses the network boundary as untrusted, and enforce a consistent policy where such data is:

  • validated and normalized early,
  • passed around as plain data rather than embedded directly into HTML or scripts,
  • and encoded at the point of rendering according to the output context.

Codifying these rules in coding standards, code review checklists, and SSR framework utilities helps prevent similar XSS bugs in routing and other SSR-related features.

Find out what's already
exploitable in your codebase.