CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



GHSA-X7MM-9VVV-64W8
8.1

GHSA-X7MM-9VVV-64W8: Reflected Cross-Site Scripting in unhead Streaming SSR

Amit Schendel
Amit Schendel
Senior Security Researcher

Apr 11, 2026·5 min read·1 visit

PoC Available

Executive Summary (TL;DR)

Reflected XSS in unhead's streaming SSR allows unauthenticated attackers to execute arbitrary JavaScript in the victim's browser via an unvalidated streamKey parameter.

The unhead package, specifically its streaming server-side rendering (SSR) functionality, is vulnerable to Reflected Cross-Site Scripting (XSS). The vulnerability stems from improper validation and unsafe string interpolation of the developer-configurable streamKey property when rendering inline JavaScript payload tags for client-side state hydration.

Vulnerability Overview

The unhead library provides document head management for server-side rendered (SSR) JavaScript applications. The streaming SSR implementation synchronizes state between the server environment and the client browser during hydration. This synchronization relies on a developer-configurable identifier known as the streamKey.

GHSA-X7MM-9VVV-64W8 tracks a Cross-Site Scripting (XSS) vulnerability classified under CWE-79: Improper Neutralization of Input During Web Page Generation. The flaw resides in the specific sub-packages responsible for handling streaming SSR, such as @unhead/ssr.

When the streamKey parameter is derived from untrusted input, the application fails to sanitize or validate the string before interpolating it into an inline script tag. The resulting output is rendered directly into the HTML document, permitting unauthenticated attackers to execute arbitrary JavaScript in the context of the user's browser session.

Root Cause Analysis

The vulnerability originates from unsafe string interpolation within the createBootstrapScript function. This function generates a bootstrapping script payload required for the client-side hydration process. The script initializes an array on the global window object using the streamKey variable as the property name.

In the vulnerable implementation, the streamKey string is directly appended to the window. object reference without prior lexical validation. The system implicitly trusts that the provided string strictly conforms to valid JavaScript identifier naming conventions.

If the streamKey configuration relies on dynamically parsed query parameters or multi-tenant headers without intermediary sanitization, an attacker gains direct control over the injected string. The JavaScript parser evaluates the raw input as code, breaking the intended dot-notation assignment and allowing execution of contiguous JavaScript expressions.

Code Analysis

The flaw manifests in packages/unhead/src/stream/server.ts. The original createBootstrapScript function utilized standard template literals to construct the payload.

// Vulnerable implementation example
export function createBootstrapScript(streamKey: string = DEFAULT_STREAM_KEY): string {
  return `<script>window.${streamKey}={_q:[],push(e){this._q.push(e)}}</script>`
}

The remediation, introduced in commit 64b5ac0aa30cc256ea6677ce3dc4f132f81b2ff6, implements strict input validation. The fix introduces a regular expression, VALID_STREAM_KEY_RE, which restricts the streamKey to standard ASCII JavaScript identifiers.

// Patched implementation with validation
const VALID_STREAM_KEY_RE = /^[$_a-z][$\w]*$/i
 
function assertValidStreamKey(streamKey: string): void {
  if (typeof streamKey !== 'string' || !VALID_STREAM_KEY_RE.test(streamKey)) {
    throw new Error(
      `[unhead] Invalid streamKey: must be a valid JavaScript identifier...`
    )
  }
}

The developers injected the assertValidStreamKey validation routine at three distinct lifecycle junctions. The system now validates the key upon entry in createStreamableHead, upon retrieval via getStreamKey, and immediately before code generation in createBootstrapScript. This layered defense strategy prevents malicious payloads from advancing to the rendering stage.

Exploitation

Exploitation requires the attacker to influence the streamKey variable passed to the server-side rendering logic. This precondition is met if an application routes unvalidated request parameters, such as a user-controlled subdomain or URL query string, directly into the unhead configuration object.

An attacker constructs a payload that properly terminates the intended JavaScript statement before initiating an arbitrary function call. A standard proof-of-concept payload utilizes a semicolon to separate expressions, followed by the malicious code and a trailing comment indicator.

Payload structure: __unhead__;alert(1)//

When the SSR engine processes this input, it generates the following HTML output:

<script>window.__unhead__;alert(1)//={_q:[],push(e){this._q.push(e)}}</script>

The browser's JavaScript engine evaluates the first expression, window.__unhead__;, which functions as a valid property access. It subsequently executes the injected function call alert(1). The trailing // converts the remainder of the original bootstrapping template into a comment, circumventing syntax errors that would otherwise halt script execution.

Impact Assessment

Successful exploitation results in Reflected Cross-Site Scripting. Because the injected script executes within the context of the vulnerable application's origin, the attacker inherits the permission scope of the victim's browser session.

The execution allows an attacker to access sensitive DOM elements, extract authentication tokens stored in localStorage or sessionStorage, and hijack active user sessions. Furthermore, the attacker can silently issue unauthorized HTTP requests on behalf of the authenticated user to restricted internal application programming interfaces.

The vulnerability primarily affects end users accessing the compromised uniform resource locator. Administrative users interacting with the malicious link face higher exposure, as session compromise in elevated contexts facilitates broader administrative control over the application infrastructure.

Remediation

The primary remediation strategy requires upgrading the unhead dependency to a version encompassing commit 64b5ac0aa30cc256ea6677ce3dc4f132f81b2ff6. The patch natively rejects any dynamically generated streamKey that contains non-alphanumeric or special characters outside the bounds of the VALID_STREAM_KEY_RE regular expression.

If an immediate dependency upgrade is administratively unfeasible, security engineers must implement input sanitization upstream of the unhead configuration instantiation. All request-derived data mapped to the streamKey parameter must undergo strict validation enforcing an allow-list of known-good identifiers.

Network defense teams can deploy web application firewall rules configured to monitor for anomalous identifier patterns. Specifically, rules targeting the presence of semicolons, parentheses, or comment structures within parameters destined for SSR state hydration endpoints will effectively interrupt exploitation attempts.

Official Patches

unjsCommit 64b5ac0 resolving the streamKey interpolation vulnerability

Fix Analysis (1)

Technical Appendix

CVSS Score
8.1/ 10
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N

Affected Systems

unhead@unhead/ssr

Affected Versions Detail

Product
Affected Versions
Fixed Version
unhead
unjs
All versions lacking commit 64b5ac0Version containing commit 64b5ac0
AttributeDetail
CWE IDCWE-79
Attack VectorNetwork
CVSS Score8.1
Exploit StatusProof of Concept
ImpactHigh
KEV StatusNot Listed

MITRE ATT&CK Mapping

T1190Exploit Public-Facing Application
Initial Access
T1059.007Command and Scripting Interpreter: JavaScript
Execution
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

The software does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.

Known Exploits & Detection

Research AnalysisProof of concept payload utilizing inline script comment truncation to achieve execution.

Vulnerability Timeline

Fix commit pushed to repository
2026-04-10

References & Sources

  • [1]GitHub Security Advisory: GHSA-X7MM-9VVV-64W8
  • [2]Fix Commit in unhead repository
  • [3]unhead Project Repository

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.