-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The regex was added to prevent markup injection\n\n`REGEX_VALID_TAG_NAME` is exported from `packages/svelte/src/utils.js`. The maintainers wrote ten lines of comment above it to name its role:\n\n```javascript\n// Matches valid HTML/SVG/MathML element names and custom element names.\n// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name\n//\n// Standard elements: ASCII alpha start, followed by ASCII alphanumerics.\n// Custom elements: ASCII alpha start, followed by any mix of PCENChar (which\n// includes ASCII alphanumerics, `-`, `.`, `_`, and specified Unicode ranges),\n// with at least one hyphen required somewhere after the first character.\n//\n// Rejects strings containing whitespace, quotes, angle brackets, slashes, equals,\n// or other characters that could break out of a tag-name token and enable markup injection.\n\nexport const REGEX_VALID_TAG_NAME =\n\t/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9.\\-_\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F-\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u{10000}-\\u{EFFFF}]+)*$/u;\n```\n\nThe regex's purpose, in the maintainers' own words, is to keep characters that \"break out of a tag-name token\" away from the renderer. It is a defensive primitive. The threat it was written against is markup injection, the canonical web-framework concern about user-controllable HTML.\n\nSix lines down the same package, `packages/svelte/src/internal/server/index.js` exports the runtime function that backs `` in SSR:\n\n```javascript\nexport function element(renderer, tag, attributes_fn = noop, children_fn = noop) {\n\trenderer.push('');\n\n\tif (tag) {\n\t\tif (!REGEX_VALID_TAG_NAME.test(tag)) {\n\t\t\te.dynamic_element_invalid_tag(tag);\n\t\t}\n\t\trenderer.push(`<${tag}`);\n\t\tattributes_fn();\n\t\trenderer.push(`>`);\n\n\t\tif (!is_void(tag)) {\n\t\t\tchildren_fn();\n\t\t\tif (!is_raw_text_element(tag)) {\n\t\t\t\trenderer.push(EMPTY_COMMENT);\n\t\t\t}\n\t\t\trenderer.push(``);\n\t\t}\n\t}\n\n\trenderer.push('');\n}\n```\n\nThe `tag` argument arrives from the compiled output of any `` in any Svelte 5 component rendered server-side. The regex `.test()` runs synchronously on the SSR worker's Node event loop, before any byte of the response is written. The gate has to clear before the renderer concatenates `<${tag}`.\n\nThat is the wiring: a defensive validator, designed to reject markup-breaking characters, run synchronously on attacker-controlled input on the server-side hot path. CVE-2026-42567 is what happens when the same wiring is exercised by an input the gate rejects.\n\n## The outer quantifier owns dashes the inner quantifier can also own\n\nStrip the comment. Strip the Unicode ranges. The pre-patch regex is structurally:\n\n```\n/^[a-zA-Z][a-zA-Z0-9]*(-[CHARS]+)*$/u\n```\n\nwhere `CHARS` is a character class that includes `a-zA-Z0-9`, the literal `.`, the literal `-`, the literal `_`, and the PCENChar Unicode ranges.\n\nThe grammar the maintainers were reaching for: an HTML standard element name (ASCII alpha plus alphanumerics) or a custom element name (a hyphen-separated identifier whose segments can contain PCENChar characters). The custom-elements spec treats the hyphen as the segment separator. The regex encodes the same grammar two ways: the outer `(-[CHARS]+)*` says \"zero or more hyphen-separated segments,\" and the inner `[CHARS]+` says \"each segment contains one or more characters from the PCENChar set.\"\n\nThe structural mistake is that the inner `CHARS` set contains the literal hyphen. PCENChar lists `-` as a valid intra-segment character; the regex inherits that. So the same byte, a `-`, can be consumed either as the leading literal `-` of the next outer iteration or as a character inside the current inner `+`. Two readings of the same input.\n\n`(-X+)*` with `-` inside `X` is the textbook nested-quantifier ReDoS shape. For an N-hyphen input followed by a character that fails the trailing `$`, the engine can partition the hyphen run into outer iterations in any of `2^(N-1)` ways, and a failing terminator forces it to try them all.\n\nThe upstream regression test that ships with the patch picks the smallest convincing payload:\n\n```typescript\ntest('REGEX_VALID_TAG_NAME no ReDoS', () => {\n const before = performance.now();\n REGEX_VALID_TAG_NAME.test('a-----------------------------------!');\n const after = performance.now();\n if (after - before > 10) {\n throw new Error(`REGEX_VALID_TAG_NAME is vulnerable to ReDoS`);\n }\n});\n```\n\nThirty-five hyphens and an exclamation mark. The leading `a` matches `^[a-zA-Z]`. The second class `[a-zA-Z0-9]*` matches empty. The engine now reaches `(-[CHARS]+)*` with `-----------------------------------!` left to consume. Each iteration eats one leading `-` and at least one character from `CHARS`. `CHARS` includes `-`, so each iteration can eat any number of trailing hyphens. The engine tries every partition. The `!` at the end fails `$`. The engine backtracks through `2^34` partitions. On a Node SSR worker, the regex does not return for the rest of the request lifecycle, and because Node's event loop is single-threaded per worker, neither does anything else that worker is handling.\n\nThe CVSS vector for CVE-2026-42567 reads `AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`. Availability High, network-reachable, no authentication, no user interaction. The advisory frames the impact as \"exhausting computational resources through regex backtracking.\" Read in reverse: the worker is hung by a 36-character body.\n\n## The patch flattens the quantifier; it does not change the grammar\n\nThe commit that ships the fix, `d2375e2ebcab5c88feb5652f1a9d621b8f06b259`, has commit message `fix: harden regex`. The diff is one line:\n\n```diff\ndiff --git a/packages/svelte/src/utils.js b/packages/svelte/src/utils.js\n@@ -491,7 +491,7 @@ export function is_raw_text_element(name) {\n // Rejects strings containing whitespace, quotes, angle brackets, slashes, equals,\n // or other characters that could break out of a tag-name token and enable markup injection.\n export const REGEX_VALID_TAG_NAME =\n-\t/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9.\\-_\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F-\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u{10000}-\\u{EFFFF}]+)*$/u;\n+\t/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9.\\-_\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F-\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u{10000}-\\u{EFFFF}]*)?$/u;\n```\n\nTwo characters changed at the tail of the outer group. The pre-patch shape is `(-[CHARS]+)*`. The post-patch shape is `(-[CHARS]*)?`. The required-then-repeated nested group becomes a single optional non-repeated group.\n\nThe inner character class still contains `-`. The patch did not remove it. PCENChar still admits intra-segment hyphens; the maintainers preserved the character set the comment describes. What they removed is the engine's option to partition the hyphen run across multiple outer iterations, because there are no outer iterations anymore. The matcher has exactly one structural path through any run of hyphens: greedy consumption inside the single optional inner `*`. No backtracking is possible because there is no ambiguity for the engine to backtrack into.\n\nThe accepted language is materially unchanged for any input that would reach a sensible developer's keyboard. The pre-patch regex matched `my-custom-element` in a single outer iteration, with the inner `[CHARS]+` greedily consuming `custom-element` because `-` is in `CHARS`. The post-patch regex matches the same string by the same path: one optional segment whose inner class consumes `custom-element` in a single pass. A caller who only ever passes valid custom-element names sees no behavioral change. A caller who passes `a-----------------------------------!` sees the regex return in microseconds instead of geological time.\n\nThis is not grammar repair. The grammar the comment describes is still encoded in the same wrong way: the segment separator is a member of the segment alphabet, so the regex would still be linguistically ambiguous if any caller cared. The patch repairs only the engine's worst case, by removing the structural feature the worst case depends on.\n\n## The \"unconstrained tag length\" caveat is the application-developer footgun\n\nThe GHSA advisory carries a narrowing clause: \"The vulnerability only affects applications that accept unconstrained tag lengths. Systems using predefined tag lists or enforcing length restrictions remain unaffected.\" A developer reading the advisory may take that as reassurance.\n\nIt is not reassurance. It is a description of the population.\n\n`` is the runtime escape hatch for any Svelte component that needs to pick the wrapping element name at render time. The canonical use cases are the ones that hand the choice to a non-developer: a CMS block whose author picks `h2` or `h3`, a Markdown extension that maps shortcodes to wrapping tags, a low-code page builder whose editor surface exposes \"wrap in \" as a configurable, a Notion-style block model where each block carries a tag-name field. Every one of those wirings is \"the tag string comes from a content database, which is downstream of an HTTP form, which is downstream of an authenticated user.\" Authenticated is not the same as trusted; in a multi-tenant CMS, an editor at one tenant is an unauthenticated attacker to every other tenant whose pages share a Node worker.\n\nThe defensive convention the framework expects is that the application layer enforces a length cap or an allowlist before the string reaches ``. The framework does not enforce either. The character set the regex rejects (whitespace, quotes, angle brackets, slashes, equals) does not include the byte the worst case is built from (the literal `-`, which is a legal custom-element character). The regex's accept criterion is \"the string looks like a tag name.\" A 36-byte string of hyphens looks enough like one to drive the engine into its worst case before the validator decides the verdict.\n\n## The reject branch is what costs\n\nA regex matcher built on backtracking has two cost regimes. The accept regime is the cost of finding any single path through the input that reaches the trailing anchor. The reject regime is the cost of proving no such path exists. The first regime terminates the moment a match is found. The second regime terminates only when every possible path has been tried.\n\nThe accept regime for `REGEX_VALID_TAG_NAME` is linear in the input length for any string that the grammar accepts. The reject regime, before the patch, was exponential in the count of trailing hyphens for any string that fails the trailing anchor. The accept path is what the comment block describes. The reject path is what the comment block does not.\n\nThe validator's defensive purpose is rejection. Its caller, the SSR runtime, invokes it for exactly the reason that rejection might be required: the input is untrusted and the output is markup. The validator's job is to make rejection happen as often as the input requires. The validator's worst case is the same path.\n\nWe are naming the class: **validation is the cost**. A defensive validator whose acceptance is cheap and whose rejection requires exhaustive search puts the rejection cost on the attacker's clock. The validator's accept set is the strings the caller would have allowed anyway. The validator's reject set is everywhere else, and the attacker selects the input from anywhere in either set. When the rejection path's worst-case cost grows without bound with respect to input length, the gate's defensive utility and the gate's DoS primitive are the same artifact.\n\nCWE-1333 names the engine-shape symptom (inefficient regular expression complexity). The pattern is larger than regex engines. Any input validator whose runtime is bounded only by the input distribution it expects, called on an input distribution the attacker chooses, has the same shape.\n\n## The release notes say \"fix: harden regex\"\n\nThe Svelte 5.55.7 release shipped on May 14, 2026. Five bullets, in order:\n\n1. `fix: prevent XSS on hydratable from user contents`\n2. Devalue dependency bump\n3. `fix: disallow empty attribute names during SSR`\n4. `fix: harden regex`\n5. `fix: move Svelte runtime properties to symbols`\n\nBullet four is this CVE. The bullet does not name ``. The bullet does not name `REGEX_VALID_TAG_NAME`. The bullet does not name ReDoS. The bullet does not link the advisory. The changeset filename, `.changeset/proud-dogs-go.md`, contains the same four-word phrase and nothing else.\n\nThe advisory was published twenty-six days later, on June 9, 2026. The advisory deliberately does not quote the regex. The advisory does not link the commit. A reader following the advisory's reference list reaches the release-notes page and reads `fix: harden regex`. A reader following the release-notes page does not reach the advisory.\n\nThis is not concealment. It is the modal disclosure shape for a CVE in a popular framework: the patch ships in the next routine release, the advisory points at the release, the release does not point at the advisory, and the commit that closes the gap is one of five bullets in a changelog whose other bullets touch unrelated subsystems. The reader who reads both connects the dots. The reader who reads either alone does not.\n\nFor twenty-six days, the patch was a public commit on a high-visibility repository and the CVE was not yet a record. Anyone reading the Svelte git log during that window had the disclosure. Anyone running 5.51.5 through 5.55.6 in production and watching the CVE feed instead did not.\n\nPoC: [sveltejs/svelte advisory GHSA-9rmh-mm8f-r9h6](https://github.com/sveltejs/svelte/security/advisories/GHSA-9rmh-mm8f-r9h6)","closing_line":"The accept path is constant. The reject path is whatever the attacker types.","hook_md":"Above line 494 of `packages/svelte/src/utils.js`, ten lines of comment tell you what the regex is for. It rejects whitespace, quotes, angle brackets, slashes, equals, \"or other characters that could break out of a tag-name token and enable markup injection.\" It is an XSS gate. Six lines further down the file tree, in `packages/svelte/src/internal/server/index.js`, the Svelte 5 SSR runtime calls the same regex against the user-supplied `tag` field of `` before concatenating that value into the response stream. CVE-2026-42567 is the input `a-----------------------------------!`, thirty-five hyphens and a terminator, hanging the SSR worker the gate was meant to protect.","post_id":641,"slug":"svelte-cve-2026-42567-reject-path-is-the-primitive","title":"CVE-2026-42567: Svelte's `` Tag Validator Hangs On Strings It Was Written To Reject","type":"initial","unreadable_sentence":"The accept path is constant. The reject path is whatever the attacker types."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCauZJfgAKCRDeZjl4jgkQ JvWOAQDgbpkglPiD6ZHCBsyLAL8FxPRz+bpzn2iDC83FB8YDqwD9H4gVEcTf1uWj 2WzQnHjRmnL0ObfTn3p/K01PrXpfDQQ= =7sKu -----END PGP SIGNATURE-----