//nefariousplan

CVE-2026-42599: Svelte's Spread Filter Required Names To Start With `on`. The HTML Parser Strips Whitespace First.

vendor

patterns

cve

proof of concept

On February 18, 2026, Svelte 5.51.5 shipped a one-line patch for CVE-2026-27121. The line, added to packages/svelte/src/internal/server/index.js in the attributes() function: if (name.length > 2 && name.startsWith('on')) continue;. Eighty-five days later, Svelte 5.55.7 shipped a second patch to the same function, addressed by GHSA-pr6f-5x2q-rwfp and tracked as CVE-2026-42599. The new patch adds one condition to a different line. The test file is the same spread-attributes-event-handler-xss/main.svelte. Five new keys have been added to it: ' onload', '\tonload', '\u00a0onload', '\t', and ''. The patch closes those five cases. The component that produced both CVEs is unchanged.

The 5.51.5 patch said what it was for

The February 18, 2026 commit (a0c7f289) carries the changeset title "fix: strip event handlers during SSR". The diff to packages/svelte/src/internal/server/index.js is three lines, inside the attributes() function that handles spread attributes during server-side rendering:

+		// omit event handler attributes
+		if (name.length > 2 && name.startsWith('on')) continue;
+

That is the entire mechanism. For every key in the attribute object, before the renderer emits it into the HTML output, the key is tested: is its length greater than two, and do its first two characters spell on. If yes, skip. The companion test file spread-attributes-event-handler-xss/main.svelte, created in the same commit, declares the input the test verifies:

<script>
	const userdata = {
		id: 'profile-123',
		class: 'card',
		onclick: 'alert(1)',
		onerror: 'alert(1)',
		onfocus: 'alert(1)',
		onmouseover: 'alert(1)'
	};
</script>

<div {...userdata}>content</div>
<img src="x" alt="photo" {...{ onerror: 'alert(1)', onload: 'alert(1)' }} />

The expected output asserts:

<div id="profile-123" class="card">content</div>

<img src="x" alt="photo" />

Six event-handler names tested. Every one starts with the literal characters on. Every one is longer than two characters. Every one is caught by name.startsWith('on'). The filter and the test describe the same syntactic object: an attribute name whose first two characters are o and n. As a description of the attacker's primitive, this is incomplete in a way the test cases could not surface, because the inputs were chosen by the same author who chose the filter.

The HTML parser does not require an attribute name to start where the JavaScript string starts

Inside the spread loop, name is a key off a plain object. After the denylist checks, the renderer hands the key to attr() in packages/svelte/src/internal/shared/attributes.js:

export function attr(name, value, is_boolean = false) {
	if (value == null || (!value && is_boolean)) return '';
	const normalized = (has_own_property.call(replacements, name) && replacements[name].get(value)) || value;
	const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;
	return ` ${name}${assignment}`;
}

The return value is a leading space, then the key, then the assignment. The leading space the function prepends is a separator between this attribute and whatever came before it. The key itself is interpolated verbatim, with no further inspection.

For an object key whose JavaScript representation is ' onload', the emitted text becomes <space> onload="alert(1)". The space attr() prepended is one character; the leading space of the key is the next character. Concatenated onto the open tag, the HTML the browser receives reads:

<div  onload="alert(1)" id="profile-123" class="card">content</div>

The HTML5 tokenization specification handles whitespace between attributes by consuming one or more whitespace characters before each attribute name. Two spaces, a tab, a non-breaking space all collapse into the same "this is where the next attribute begins" state. When the parser advances past the leading whitespace, the next attribute name is onload. The element's event-handler set picks up onload, and a click, mouseover, or initial layout event triggers the inline handler.

The JavaScript filter inspected the key as a string and asked "does this string begin with the characters o then n". The HTML parser inspected the same characters as a token stream and asked "where, past any whitespace separators, does the next attribute name begin". The two grammars describe the same syntactic object, an event-handler attribute name, and they do not agree about where the name starts. This is the gate-narrower-than-sink shape the catalog has accumulated across shell-quote's regex character class against POSIX sh and Starlette's request.url.path against the ASGI router. One grammar checks; one grammar runs. The bypass is the gap.

The 5.55.7 patch enumerates five more shapes

The May 14, 2026 commit (547853e2), addressed in CVE-2026-42599 and GHSA-pr6f-5x2q-rwfp, carries the changeset title "fix: disallow empty attribute names during SSR". The diff inside the same attributes() function changes one line:

-		if (INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;
+		if (name === '' || INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;

The companion change is in the test file. The original four event-handler keys are kept. Five new keys are added:

const userdata = {
	id: 'profile-123',
	class: 'card',
	onclick: 'alert(1)',
	onerror: 'alert(1)',
	onfocus: 'alert(1)',
	onmouseover: 'alert(1)',
	' onload': 'alert(1)',
	'\tonload': 'alert(1)',
	'\u00a0onload': 'alert(1)',
	'\t': '/onmouseover=alert(1)//',
	'': '/onmouseover=alert(1)//'
};

Each addition is a shape the 5.51.5 filter passed through.

  • ' onload', leading ASCII space. ' onload'.startsWith('on') returns false. The browser's whitespace consumption strips the space and registers onload.
  • '\tonload', leading horizontal tab. '\tonload'.startsWith('on') returns false. The browser strips the tab and registers onload.
  • '\u00a0onload', leading non-breaking space. '\u00a0onload'.startsWith('on') returns false. The HTML tokenizer treats U+00A0 as ASCII whitespace for attribute-list parsing in the lenient browsers the framework supports, and registers onload.
  • '\t', a key whose entire string content is a tab. '\t'.startsWith('on') is false; length is one. Before the patch, the renderer would emit \t="/onmouseover=alert(1)//". The browser sees a malformed attribute whose value the lenient parser extracts onmouseover=alert(1) from.
  • '', the empty string. Length zero. Before the patch, the renderer emitted ="/onmouseover=alert(1)//". Same lenient-parser extraction of onmouseover from the value side of the malformed attribute.

The new condition catches all five. INVALID_ATTR_NAME_CHAR_REGEX is /[\s'">/=\u{FDD0}-\u{FDEF}...]/u, with the u flag. In Unicode-flag regex, \s matches U+00A0 along with every other whitespace code point the HTML tokenizer's separator class covers. Names containing whitespace are rejected. Names containing =, >, /, or " are rejected. The empty-string case earns its own equality check because the regex character class does not match against the empty string. Eighty-five days after the first patch, the filter has been widened to describe approximately what the HTML parser was already doing in 5.51.5.

What the patch still does not enumerate

The full post-5.55.7 filter chain inside attributes() reads, in order:

for (name of Object.keys(attrs)) {
	if (typeof attrs[name] === 'function') continue;
	if (name[0] === '$' && name[1] === '$') continue;
	if (name === '' || INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;

	var value = attrs[name];
	var lower = name.toLowerCase();

	if (lowercase) name = lower;

	// omit event handler attributes
	if (lower.length > 2 && lower.startsWith('on')) continue;
	// ...
	attr_str += attr(name, value, is_html && is_boolean_attribute(name));
}

It is a denylist. Functions are denied because Svelte's reactivity puts function values on attribute objects. Keys with the $$ prefix are denied because the compiler uses double-dollar as an internal marker. Empty and invalid-character names are denied because the HTML parser tolerates them as bypasses to the next clause. Names that lowercase to begin with on are denied because they map to event handlers. Everything else is emitted to the HTML output verbatim, with the value escaped only for double quotes and angle brackets.

<iframe srcdoc> is not on the denylist. Spreading an attacker-controlled object onto an <iframe> element lets the value of the srcdoc key become a parsed HTML document inside the iframe, where event handlers fire under normal hydration order because there is no hydration walker inside the iframe. <a href> accepts javascript: URLs and is not on the denylist. <form action> and <input formaction> are not on the denylist; spreading a form attribute lets the attacker redirect submissions to an attacker-controlled origin. <meta http-equiv="refresh"> content is not on the denylist. The component that the patches addressed continues to spread untrusted object keys into the HTML output. The patches addressed one of the primitives that component reaches. The component itself, attributes() in internal/server/index.js, remains the seam between attacker-controlled object keys and the browser's attribute tokenizer.

The hydration clause in the advisory is the upper bound, not the precondition

GHSA-pr6f-5x2q-rwfp says: "this vulnerability only triggers if the user's browser has JavaScript enabled but Svelte's hydration mechanism does not reach the vulnerable element before the event fires." The phrasing implies a narrow race condition. The race is between the browser's HTML parser, which finishes registering the onload attribute as soon as the tag's closing > arrives, and Svelte's hydration walker, which traverses the parsed DOM in document order and removes the inline event handlers the framework did not generate.

For onload, the race is unwinnable in the general case. The browser fires onload on an <img> element when the network fetch for the image completes, which routinely happens before hydration reaches that element on any page with more than trivial content. For onmouseover, the race is unwinnable on any page where the cursor enters the affected element before the hydration bundle has loaded. For onerror, the race is unwinnable when the image fails to load, which the attacker controls by choosing the src. The advisory's "only triggers if hydration does not reach the vulnerable element" is the latest moment after which the bug stops firing. It is not a precondition the application can satisfy.

Two patches, one component

The February changeset said "strip event handlers during SSR". The May changeset said "disallow empty attribute names during SSR". Both patches strip what their author believed was the next layer of attribute-name shapes the HTML parser interprets as event handlers. Neither patch changes the design that puts an enumerated denylist between an attacker-controlled object and the HTML output. The test file holding both CVEs' inputs is named spread-attributes-event-handler-xss. Two commits, eighty-five days apart, the same component, the same test directory, the same shape of fix: attributes() is a design-debt driver, and the design is what holds the primitive between CVE-2026-27121 and CVE-2026-42599.

PoC: github.com/sveltejs/svelte

The next class of name the filter does not enumerate and the parser does interpret will close the next CVE.