Sep 30, 2026·7 min read·6 visits
A failure to sanitize script-closing tags in serialize-javascript v7.1.1 allows unauthenticated Cross-Site Scripting (XSS) when serializing user-influenced function values embedded in HTML script elements.
A security vulnerability in serialize-javascript v7.1.1 allows Cross-Site Scripting (XSS) due to an overly greedy regular expression (SCRIPT_CLOSE_REGEXP) used during function serialization. Two secondary defects involving a spoofed toString() validation bypass and a stateful native code validator are also addressed in the fixed version v7.1.2.
serialize-javascript is a widely utilized Node.js library designed to serialize JavaScript objects into a format that is a superset of JSON. Unlike standard JSON serialization, this library supports serializing complex JavaScript types, including regular expressions, dates, maps, sets, and custom functions. This capability makes it a popular choice for server-side rendering (SSR) frameworks, where the application state needs to be serialized on the server and hydrated on the client-side inside HTML templates.
The attack surface is introduced when the application accepts user-influenced inputs that are subsequently processed as function values or custom code structures and serialized. If the output of this serialization is directly embedded within a client-side <script> tag, a failure in the library's sanitization routine allows arbitrary HTML injection. This leads to a Cross-Site Scripting (XSS) vulnerability within the origin of the hosting web page.
The vulnerability, identified as CVE-2026-97711, is caused by a failure to safely neutralize script-closing tags (</script>) within serialized function bodies. The regression was introduced in version 7.1.0 and persisted in version 7.1.1. In addition to the primary XSS vector, researchers identified two secondary flaws involving a spoofed toString() prototype bypass and a statefulness issue in the native code validation pattern, both of which are addressed in version 7.1.2.
The primary vulnerability lies in the implementation of the SCRIPT_CLOSE_REGEXP regular expression used to neutralize script tags. The library attempts to identify and sanitize closing script tags using the regular expression /</script[^>]>/gi. The negated character class [^>] is designed to match any characters following </script until a closing bracket > is encountered. However, this class is overly greedy because it does not exclude the less-than character <.
When a function body contains a syntax construct that mimics a regular expression division operator, such as x</script=+/, the engine treats </script as part of the code structure. If a valid </script> tag appears later in the same function source code, the greedy character class matches the entire span between the first </script and the final >. Because the matching pattern spans across tag boundaries, the intermediate characters, including the subsequent < character, are consumed as a single match.
During serialization, the escaping routine only neutralizes the leading bracket of the matched range. The remainder of the matched string, which contains the actual active </script> tag and any subsequent payload, is emitted into the output stream completely unmodified. When the final payload is parsed by the client's web browser, the unescaped closing tag forces an early exit from the script parsing context, causing the browser to interpret the remaining string as raw HTML.
Additionally, the library suffered from a type-confusion flaw. The serialization routine relied on fn.toString() returning a primitive string to execute character escaping. Attackers could supply an object disguised as a function with an overridden toString method returning an object with a custom replace method. This hijacked the standard string replacement routine, returning the original unsafe string without applying any sanitization. Finally, the regular expression IS_NATIVE_CODE_REGEXP utilized a global /g flag, which preserved the lastIndex pointer. This statefulness resulted in every second sequential native function bypass verification, allowing native function serialization.
Let's analyze the critical changes introduced in the codebase to resolve these issues. The patch corrects the regular expressions and enforces strict type checks on the return value of toString().
// Vulnerable SCRIPT_CLOSE_REGEXP in v7.1.1
var SCRIPT_CLOSE_REGEXP = /<\/script[^>]*>|<\/script(?=[\t\n\f\r \/>])/gi;
// Patched SCRIPT_CLOSE_REGEXP in v7.1.2
// By replacing [^>]* with [^<>]* we ensure that the match
// cannot span past a newly opened tag character. This prevents
// swallowing an entire second </script> tag into a single match block.
var SCRIPT_CLOSE_REGEXP = /<\/script[^<>]*>|<\/script(?=[\t\n\f\r \/>])/gi;The modification to exclude < prevents the regular expression engine from traversing across tag boundaries. If there is a subsequent < character, the match terminates, ensuring that each individual closing script tag is identified as an independent match and correctly escaped.
In addition, the fix introduces an explicit type check within the serializeFunc function to prevent object type confusion attacks:
function serializeFunc(fn, options) {
var serializedFn = fn.toString();
// Security Fix: Prevent spoofed toString() from returning a non-string
// object that implements its own bypass-friendly replace() method
if (typeof serializedFn !== 'string') {
throw new TypeError('Function.toString() must return a string');
}
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) {
throw new TypeError('Serializing native function: ' + fn.name);
}
// ... escaping logic ...
}Finally, the global flag /g was removed from the native code validator: var IS_NATIVE_CODE_REGEXP = /{\s*[native code]\s*}/;. This makes the regex stateless, ensuring that .test() consistently evaluates starting from index zero, resolving the sequential check bypass vulnerability.
Exploiting CVE-2026-97711 requires specific prerequisites. An attacker must have the ability to supply code or influence properties of an object that is subsequently serialized by serialize-javascript and rendered inside a script block. The vector relies on the target application executing server-side rendering of client-side state where functions are serializable.
The layout of the exploit payload relies on combining a JavaScript division context and an HTML injection string. The structure is designed to satisfy both the JavaScript parser and the HTML parser, leveraging the difference in how they interpret regular expression symbols. Consider the following sequence of execution:
When the browser parses the generated script element, it does not understand JavaScript string boundaries during the initial tokenization phase. The HTML tokenizer reads character by character looking for </script followed by whitespace, a slash, or a closing bracket. Because the payload contains a valid, unescaped </script> tag that survived serialization due to the greedy match, the HTML parser halts script execution and processes the trailing <img src=x onerror=alert(document.domain)> tag as an active HTML element, resulting in client-side script execution.
The impact of this vulnerability is client-side code execution in the context of the user's browser session. By achieving Cross-Site Scripting (XSS), an attacker can access sensitive session identifiers, such as cookies and local storage tokens, execute arbitrary actions on behalf of the user, or rewrite the DOM to present credential harvesting overlays.
The Common Vulnerability Scoring System (CVSS) v4.0 score is rated as 2.3 (Low). This low rating is attributed to the low direct impact on the backend platform's confidentiality, integrity, and availability (VC:N/VI:N/VA:N). However, the subsequent system impact parameters for confidentiality and integrity are both rated as Low (SC:L/SI:L), reflecting the standard localized impact profile of an XSS vulnerability on a web client.
Despite its low CVSS score, organizations utilizing server-side rendering with client-side state hydration must evaluate the risk in their specific operational contexts. If an application serializes state objects derived from untrusted user inputs, this issue allows complete compromise of the client-side session. The exploit maturity is classified as a Proof of Concept (PoC) as functional demonstration payloads are public.
The recommended remediation is to upgrade serialize-javascript to version 7.1.2 or higher. This update resolves the greedy regular expression matching, enforces strict type-checking on Function.toString() returns, and removes the stateful global flag from the native code validator, preventing all three identified bypass techniques.
If upgrading is not immediately feasible, developers should avoid serializing function values when processing untrusted inputs. If function serialization is absolutely required, the serialized output must not be rendered raw within an inline HTML <script> block. Instead, serialize the data as a JSON string and inject it into a safe, non-executable context, such as an HTML data attribute:
<!-- Secure Alternative: State Hydration via Data Attributes -->
<div id="app-state" data-state="<%= he.encode(serializedState) %>"></div>Client-side scripts can then retrieve and safely parse this attribute using JSON.parse() or dedicated deserializers. This architecture avoids placing raw executable code blocks in the HTML stream, neutralizing the risk of XSS even if the serialization library fails to completely sanitize the inputs.
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N| Product | Affected Versions | Fixed Version |
|---|---|---|
serialize-javascript Yahoo | >= 7.1.0, <= 7.1.1 | 7.1.2 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-79 |
| Attack Vector | Network (AV:N) |
| CVSS v4.0 Score | 2.3 |
| EPSS Score | N/A |
| Impact | Cross-Site Scripting (XSS) |
| Exploit Status | Proof-of-Concept |
| CISA KEV Status | Not Listed |
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
CVE-2026-128087 (GHSA-9264-jvgf-6w2f) is an incorrect behavior order (CWE-696) and improper authorization (CWE-863) vulnerability in the russh Rust SSH library, affecting versions 0.55.0 through 0.65.0. During the initial SSH key exchange (KEX) handshake, the client state machine invokes the client::Handler::kex_done() callback—providing the negotiated raw shared secret bytes—prior to validating the remote server's host key or certificate via check_server_key(). Consequently, an untrusted or rogue SSH server can complete cryptographic key agreement and force a connecting client to execute side-effecting application logic inside kex_done() before the server's identity is checked and rejected.
CVE-2026-128082 (GHSA-6vhm-j9h7-f9gh) is an uncontrolled recursion vulnerability (CWE-674) in AutoMapper, a convention-based object-object mapper for .NET. When mapping nested or self-referential types into destination models that rely on parameterized constructors, C# positional records, or recursive ConstructUsing expressions, AutoMapper evaluates child constructor arguments prior to incrementing the parent's recursion depth counter. This ordering flaw bypasses both explicit MaxDepth limits and the default depth limit of 64. An unauthenticated remote attacker can supply deeply nested input payloads to affected endpoints, exhausting the thread call stack and triggering an uncatchable System.StackOverflowException that terminates the hosting .NET process.
An information exposure vulnerability in the @opentelemetry/instrumentation-http package for OpenTelemetry JavaScript versions 0.204.0 prior to 0.222.0 causes incoming HTTP server spans to record raw, unredacted query string parameters under the url.query attribute. While outgoing client spans applied built-in and user-configured query parameter redaction, incoming server spans bypassed this sanitization completely, resulting in the transmission of sensitive credentials such as pre-signed cloud URLs and API tokens to external observability backends.
CVE-2026-128089 is an uncontrolled resource consumption vulnerability in the dnspython toolkit for Python, affecting all versions prior to 2.9.2. When parsing Well-Known Service (WKS) records from text via dns.rdtypes.IN.WKS.WKS.from_text(), the parser fails to validate that numeric service port identifiers fall within the RFC 1035 valid range of 0 through 65535. An attacker capable of supplying untrusted zone files or RDATA text strings containing an arbitrarily large service port integer can force the parser to allocate an unbounded bitmap array using an inefficient linear append loop, resulting in severe CPU exhaustion, application hangs, or Out-Of-Memory (OOM) process termination.
CVE-2026-126347 (GHSA-5cjw-f85j-cv6r) is an open redirect vulnerability (CWE-601) in Tornado, an asynchronous Python networking library and web framework. The flaw resides in tornado.web.RedirectHandler when dynamic URL redirection templates incorporate unvalidated user input. Due to a parser differential between RFC 3986 (used by Python's urllib.parse.urlsplit) and the WHATWG URL Standard (used by modern web browsers), inputs containing three or more leading slashes bypass Tornado 6.6.0's validation logic, allowing unauthenticated attackers to redirect users to arbitrary external domains.
A Denial of Service (DoS) vulnerability exists in @sveltejs/adapter-node versions 5.5.7 and 6.0.0-next.0 through 6.0.0. When a SvelteKit server route returns a direct response from a fetch() call with a Content-Type of text/event-stream, the Node.js adapter attempts to mutate the response headers to disable proxy buffering. Because headers returned directly by the WHATWG Fetch API carry an immutable guard, this mutation throws an unhandled TypeError, terminating the underlying Node.js process and denying service to all active and subsequent clients.