
Cloud Vulnerability DB
A community-led vulnerabilities database
The streaming SSR plugin in unhead interpolates its framework option directly into generated client JavaScript without validation or escaping. buildStreamingPluginOptions({ framework }) passes the value to buildClientStub(), which embeds it raw inside a single-quoted ES module import in packages/unhead/src/stream/unplugin.ts. A framework value containing a single quote breaks out of the import string literal and injects attacker-chosen code into the virtual client module that is bundled and served to every visitor's browser. This mirrors the previously fixed streamKey injection, but framework is a separate parameter on a separate code path that no release validates.
The generated client bootstrap is assembled with a template literal that places framework inside a single-quoted string without quoting, escaping, or identifier validation. The sibling streamKey value in the same function is protected both by parseStreamKey() identifier validation and by JSON.stringify() serialization, but framework receives neither. Any single quote in framework terminates the import string early, and the remainder of the value is parsed as live JavaScript rather than as a package specifier.
packages/unhead/src/stream/unplugin.ts
line 135: const key = JSON.stringify(streamKey) // streamKey escaped
line 148: return `import{createHead}from'${framework}/client' // framework raw
line 172: const streamKey = parseStreamKey(rawStreamKey) // streamKey validated; framework not
Affected function: buildClientStub (packages/unhead/src/stream/unplugin.ts:131)An integration that constructs the streaming plugin through the public createStreamingPlugin or buildStreamingPluginOptions API and sources the framework option from untrusted input (for example an environment variable, a configuration file, or a build argument) emits attacker-controlled JavaScript into the client bundle. The injected code executes in the browser of every user who loads the application, giving the attacker the standard cross-site scripting capabilities within the application origin: reading accessible cookies and page content and modifying the DOM. The four shipped framework wrappers (Vue, React, Solid, Svelte) hardcode a safe framework constant and do not expose the option, so default usage through those wrappers is not affected. This is the same configuration-sink threat model under which the streamKey variant was accepted.
Requires the unhead streaming plugin constructed via the lower-level public API with a
framework value derived from untrusted input. The snippet below shows the generated module
content produced by buildClientStub for a malicious framework value.import { buildStreamingPluginOptions } from 'unhead/stream/unplugin'
// framework sourced from untrusted input by a custom integration
const options = buildStreamingPluginOptions({
framework: "@unhead/vue';globalThis.XSS=1;//",
})
// The plugin's load hook for the client virtual module returns buildClientStub(framework, ...)
// whose first line becomes the code below.import{createHead}from'@unhead/vue';globalThis.XSS=1;///client'The import resolves to a real module, globalThis.XSS=1 runs as standalone statement, and // comments out the trailing /client'. The result is syntactically valid JavaScript that executes the injected statement in the browser.
createStreamingPlugin (packages/unhead/src/stream/unplugin.ts:480) or buildStreamingPluginOptions (packages/unhead/src/stream/unplugin.ts:163) API, which accept the full options interface including framework.framework string. The option is typed only as string (packages/unhead/src/stream/unplugin.ts:20) with no constraint.buildStreamingPluginOptions destructures framework without validation (packages/unhead/src/stream/unplugin.ts:165) and the client-module load hook calls buildClientStub(framework, streamKey, warnEnabled()) (packages/unhead/src/stream/unplugin.ts:350).framework; parseStreamKey() and JSON.stringify() cover only streamKey.buildClientStub interpolates framework raw into a single-quoted import string (packages/unhead/src/stream/unplugin.ts:148), and the load hook returns the generated code as the virtual:@unhead/streaming-client module served to the client bundle.The relevant protections are the two guards applied to the sibling streamKey value in the same function: parseStreamKey() identifier validation (packages/unhead/src/stream/key.ts:3) and JSON.stringify() escaping (packages/unhead/src/stream/unplugin.ts:135). Searching the streaming module for any equivalent treatment of framework returns nothing: framework is never passed to parseStreamKey() or wrapped by JSON.stringify() and reaches the sink at line 148 unchanged. The strongest challenge was whether the single-quote break could still yield loadable, syntactically valid module code; the payload @unhead/vue';globalThis.XSS=1;// demonstrates that it can, producing a valid import followed by an executable statement and a line comment. The seed fix (parseStreamKey(), introduced for streamKey in v3.0.1) predates the unplugin.ts file and does not cover this parameter.
npmunhead>= 3.4.0, <= 3.4.33.4.3 (npm registry)packages/unhead/src/stream/unplugin.ts file and its buildClientStub function were first introduced in v3.4.0 and remain unchanged with respect to framework handling through v3.4.3, the latest published version.framework is a safe module specifier before it reaches code generation, at the point where options are resolved in buildStreamingPluginOptions. Validate it against a strict allowlist or package-specifier pattern and reject invalid values, or serialize it with JSON.stringify() at the interpolation site in buildClientStub so it can only ever be a string literal rather than inline code. The fix should cover the single-quote break shown here as well as any other character that can terminate or escape the generated string literal. As an interim mitigation, integrations should hardcode framework to a trusted constant and never source it from untrusted input, matching the shipped framework wrappers.Reported by zx.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."