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')
A local elevation of privilege vulnerability exists in the Microsoft .NET Aspire CLI (`Aspire.Cli`) versions 13.5.4 prior to 13.6.5. When executing SDK management commands (`aspire sdk generate`, `aspire sdk dump`, and `aspire sdk export`), the CLI creates temporary project directories inside the shared operating system temporary folder (such as `/tmp` on Unix-like systems) without restricting directory permissions or disabling MSBuild automatic response file resolution. A local, low-privileged attacker on a multi-user system can place a crafted `Directory.Build.rsp` file in the shared temporary directory hierarchy. When a victim user executes an affected Aspire CLI command, MSBuild traverses upward, ingests the attacker-controlled response file, and executes arbitrary commands in the security context of the victim user.
CVE-2026-120792 is a high-severity local information disclosure vulnerability in the Microsoft .NET Aspire CLI (Aspire.Cli) affecting versions 13.5.4 prior to 13.6.5. The flaw stems from the insertion of sensitive information into a shared temporary log file (CWE-532) combined with insecure temporary file creation (CWE-377) within the DeprecatedMcpCommandScanner component. During agent configuration scanning, the CLI unconditionally appends internal workspace paths and the first 200 characters of Model Context Protocol (MCP) agent configuration files to a statically named file in the system temporary directory. On multi-user systems, unprivileged local users can read this file to harvest API keys, authentication tokens, and internal service endpoints.
CVE-2026-114159 is a heap-based buffer overflow vulnerability (CWE-122) in Microsoft.DiaSymReader.Native affecting Microsoft Visual Studio and the .NET Runtime on Windows. An integer truncation error during the parsing of oversized document names in Portable PDB symbol files causes an undersized heap allocation, leading to an out-of-bounds memory write and remote code execution.
CVE-2026-114158 is a high-severity remote code execution vulnerability affecting Microsoft Visual Studio 2026 and multiple supported servicing branches of Microsoft .NET (.NET 8.0, 9.0, 10.0, and 11.0) on Windows. The flaw resides in the native symbol reader library, Microsoft.DiaSymReader.Native, and is triggered when parsing Portable Program Database (PDB) metadata containing malformed EmbeddedSource custom debug information records. By supplying a parent Record Identifier (RID) of zero or an out-of-bounds value, an attacker causes an integer underflow during 1-based to 0-based index conversion, leading to a heap-based buffer overflow and arbitrary code execution within the context of the host developer tool or runtime.
CVE-2026-114151 is a high-severity remote code execution vulnerability affecting Microsoft Visual Studio 2026 and multiple supported versions of the Microsoft .NET runtime on Windows. The flaw resides in the native Debug Information Access (DIA) symbol reader component, Microsoft.DiaSymReader.Native. When parsing Program Database (.pdb) files, the component fails to validate the length of serialized numeric records (specifically LF_DECIMAL structures) before unpacking them into a fixed-size stack buffer. An attacker who convinces a user or automated diagnostic process to load a crafted .pdb file can trigger a stack-based buffer overflow, resulting in arbitrary code execution within the context of the host process.
CVE-2026-105544 is a high-severity local elevation of privilege vulnerability in Microsoft .NET and Microsoft.TestPlatform.CLI. Improper access control on local inter-process communication mechanisms and execution brokers allows an authorized local attacker to cross security boundaries and execute arbitrary code in the context of a higher-privileged user running a test execution cycle.