Executive brief
unhead is a JavaScript library for managing HTML head tags in server-side rendering (SSR) applications. A vulnerability in how it processes the `streamKey` configuration parameter allows an attacker to inject arbitrary JavaScript code into generated HTML pages if an application passes untrusted data into this setting. Most applications are unaffected because they use hardcoded, default, or safe custom keys; exploitation requires explicit routing of untrusted input to a developer configuration sink.
Technical details
The vulnerability is a script injection (CWE-79) stemming from insufficient input validation. The `createStreamableHead()` and `createBootstrapScript()` functions embed the `streamKey` parameter directly into inline script tags via string interpolation (e.g., `window.${streamKey}={...}`) without identifier validation or escaping. An attacker-controlled value like `__unhead__;globalThis.PWNED=1;//` breaks out of the intended dot-notation property access and injects arbitrary JavaScript. The vulnerability requires that an application explicitly routes untrusted request data into the `streamKey` configuration parameter—a pattern that is neither documented nor recommended. The fix, released in unhead 3.0.1, validates `streamKey` against a conservative ASCII JavaScript-identifier regex (`/^[$_a-z][$\w]*$/i`) at all injection points and throws immediately on invalid values.
Affected products
- unjs unhead 3.0.0-beta.5 through 3.0.0
Timeline
- 2026-04-10: disclosed: Advisory GHSA-x7mm-9vvv-64w8 published
- 2026-04-10: patched: Fixed in unhead 3.0.1 via commit 64b5ac0