-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The fix lives in TYPO3's repository, not in Masterminds'\n\nOliver Hader's commit `bd1a88d` on 2026-04-27 adds two new files to `typo3/html-sanitizer`:\n\n- `src/Parser/Html5.php`, a sixty-five-line subclass of `Masterminds\\HTML5` whose only purpose is to instantiate the local Tokenizer instead of the upstream one.\n- `src/Parser/Tokenizer.php`, a sixty-nine-line subclass of `Masterminds\\HTML5\\Parser\\Tokenizer` whose only purpose is to override `rawText()`.\n\nThen it rewires `Sanitizer::createParser()`:\n\n```diff\n-use Masterminds\\HTML5;\n+use TYPO3\\HtmlSanitizer\\Parser\\Html5;\n\n- protected function createParser(): HTML5\n+ protected function createParser(): Html5\n {\n- return new HTML5(self::mastermindsDefaultOptions);\n+ return new Html5(self::mastermindsDefaultOptions);\n }\n```\n\nNothing else changed in the parser surface. The patch is structurally a hot-patch around an upstream method the maintainer cannot edit. The docblock on the local Tokenizer states the diagnosis in twelve words:\n\n```php\n/**\n * Extends the Masterminds tokenizer to fix rawText() so that it recognises\n * whitespace-variant closing tags (e.g. ) as valid end tags per\n * HTML5 spec § 8.2.6.1, aligning it with the existing rcdata() behaviour.\n */\nclass Tokenizer extends MastermindsTokenizer\n```\n\n\"Aligning it with the existing rcdata() behaviour.\" The existing behaviour is the sibling method in the same class the TYPO3 maintainer cannot reach.\n\n## rcdata() and rawText() are twenty lines apart in the same file\n\n`Masterminds\\HTML5\\Parser\\Tokenizer.php` declares both methods. Lines 249-261 are `rawText()`. Lines 270-301 are `rcdata()`. They consume different content (HTML raw text mode vs HTML RCDATA mode) but share the same exit condition under § 8.2.6.1 of the HTML5 spec: an end-tag matching the element name, optionally followed by whitespace before `>`.\n\n`rawText()`, in the version that shipped from 2014-06-11 until today:\n\n```php\nprotected function rawText($tok)\n{\n if (is_null($this->untilTag)) {\n return $this->text($tok);\n }\n\n $sequence = 'untilTag . '>';\n $txt = $this->readUntilSequence($sequence);\n $this->events->text($txt);\n $this->setTextMode(0);\n\n return $this->endTag();\n}\n```\n\n`$sequence` is constructed with a literal trailing `>`. `readUntilSequence()` is a byte-for-byte scan. If the input contains `` and no later ``, the scan walks to EOF and returns the entire rest of the stream as text content.\n\n`rcdata()`, six lines below:\n\n```php\nprotected function rcdata($tok)\n{\n if (is_null($this->untilTag)) {\n return $this->text($tok);\n }\n\n $sequence = 'untilTag;\n $txt = '';\n\n $caseSensitive = !Elements::isHtml5Element($this->untilTag);\n while (false !== $tok && !('<' == $tok && ($this->scanner->sequenceMatches($sequence, $caseSensitive)))) {\n if ('&' == $tok) {\n $txt .= $this->decodeCharacterReference();\n $tok = $this->scanner->current();\n } else {\n $txt .= $tok;\n $tok = $this->scanner->next();\n }\n }\n $len = strlen($sequence);\n $this->scanner->consume($len);\n $len += $this->scanner->whitespace();\n if ('>' !== $this->scanner->current()) {\n $this->parseError('Unclosed RCDATA end tag');\n }\n $this->scanner->unconsume($len);\n $this->events->text($txt);\n $this->setTextMode(0);\n\n return $this->endTag();\n}\n```\n\n`$sequence` is constructed without the trailing `>`. The loop stops as soon as ``. Whitespace between the tag name and `>` is part of the contract.\n\nThe TYPO3 subclass's override of `rawText()` is, modulo the entity-reference handling rcdata uses and rawText does not, the rcdata code. Same `$sequence` without `>`. Same whitespace consume. Same `>` check. The docblock spells out the relationship.\n\n## The browser stops at the whitespace\n\nHTML5 § 8.2.6.1, \"Tokenization\", specifies the end-tag-open state: after ``. Whitespace transitions to the \"before attribute name\" state, which then accepts `>` as the tag close. Every shipping browser follows this. An end tag with a tab, newline, or space between the name and `>` is a valid end tag.\n\nThe Masterminds rawText() reads it as continuing raw text. The PoC the patch's regression test ships exercises the exact differential:\n\n```html\n',\n];\n```\n\nThe TYPO3 tokenizer now exits raw text at ``. The img element is parsed as a sibling of style, which the Behavior's tag set does not allow, which the visitor pass removes before serialization. The output contains no img.\n\n## rcdata() got the fix on 2015-02-02. rawText() did not.\n\n`git blame` on Masterminds' `Tokenizer.php`:\n\n```\ne49c4591 (Asmir Mustafic 2014-06-11) protected function rawText($tok)\ne49c4591 (Asmir Mustafic 2014-06-11) {\ne49c4591 (Asmir Mustafic 2014-06-11) if (is_null($this->untilTag)) {\ne49c4591 (Asmir Mustafic 2014-06-11) return $this->text($tok);\ne49c4591 (Asmir Mustafic 2014-06-11) }\ne49c4591 (Asmir Mustafic 2014-06-11) $sequence = 'untilTag . '>';\ne49c4591 (Asmir Mustafic 2014-06-11) $txt = $this->readUntilSequence($sequence);\n```\n\nThe `'untilTag . '>'` line is unchanged from Asmir Mustafic's 2014-06-11 commit `e49c4591`, which authored the file. The same commit authored an identical `rcdata()` whose `$sequence` was also constructed with a trailing `>`. Both methods had the same bug.\n\nEight months later, on 2015-02-02, Zhaofeng Li committed `7c1c7dfa`, title \"Allow whitespaces in RCDATA end tags,\" closing Masterminds issue #75:\n\n```diff\n- $sequence = 'untilTag . '>';\n- $txt = $this->readUntilSequence($sequence);\n+ $sequence = 'untilTag;\n+ $txt = '';\n+\n+ while (false !== $tok && !('<' == $tok && ($this->scanner->sequenceMatches($sequence, false)))) {\n+ ...\n+ }\n+ $len = strlen($sequence);\n+ $this->scanner->consume($len);\n+ $len += $this->scanner->whitespace();\n+ if ('>' !== $this->scanner->current()) {\n+ ...\n+ }\n```\n\nThe commit touched `rcdata()` and nothing else. `rawText()`, eight method declarations above in the same file, was not edited. The bug it shared with `rcdata()` stayed in place.\n\nBetween 2015-02-02 and 2026-04-27 the file received forty-six commits. None of them touched the `$sequence` line in `rawText()`. The current contents of `rawText()` in `Masterminds/html5-php` HEAD as of this writing are byte-identical to Asmir Mustafic's 2014 implementation. Four thousand one hundred and two days. Asmir wrote both methods with the same bug. Zhaofeng fixed one. The one Zhaofeng did not fix is the one CVE-2026-47344 names.\n\nThis is the [Parallel Implementation Gap](/patterns/parallel-implementation-gap) shape, with the parallelism collapsed onto sibling methods of one class in one file in one library. The canonical (`rcdata()`) imported the whitespace fix. The divergent (`rawText()`) did not. Both expose the same client-facing contract: \"consume input until the end-tag for `$untilTag` and return everything before it as text.\" One method aligned with the spec. The other ran without alignment for eleven years, two months, and twenty-five days.\n\n## TYPO3 fixed it downstream because nobody fixed it upstream\n\nThe patch does not touch `Masterminds/html5-php`. TYPO3 is a downstream consumer. The fix lives in TYPO3's `src/Parser/Tokenizer.php`, applied via the indirection of a subclass that the local `Sanitizer::createParser()` instantiates in place of the upstream's. Other consumers of `Masterminds\\HTML5\\Parser\\Tokenizer` get the unfixed `rawText()` because they instantiate the upstream tokenizer directly.\n\nThe 2022 fix was the same shape. CVE-2022-23499 closed an XSS in CDATA and raw-text elements; the commit message opens, exactly: \"Due to a parsing issue in upstream package `masterminds/html5`, malicious markup used in a sequence with special HTML CDATA sections cannot be filtered and sanitized.\" The mitigation TYPO3 shipped was a flag named `ALLOW_INSECURE_RAW_TEXT`, gated on a Behavior allowlist, with a Serializer-level pass that encodes raw text by default and waves it through only when the flag is set on the tag's Behavior. CVE-2026-47344 is what happens when that opt-in flag meets a tokenizer whose end-tag detection does not match the browser's.\n\nThe Masterminds library is the de facto PHP HTML5 parser. Drupal 9 and 10 use it via the `masterminds/html5` Composer dependency for CKEditor 5 filter integration. The Symfony HtmlSanitizer component delegates to it for parsing. Every project that does what TYPO3 does, parse untrusted HTML with Masterminds, sanitize the resulting DOM, serialize, and trust the output, inherits the same `rawText()` if it has not subclassed the tokenizer. Masterminds last shipped a release on 2025-03-06. The file in HEAD today still constructs `$sequence` with the trailing `>`.\n\nThis is [Design Debt Driver](/patterns/design-debt-driver), the upstream-parser-as-debt-source instance. TYPO3's html-sanitizer has now taken two CVE patches whose root cause the maintainer attributes in their own commit messages to Masterminds parsing behaviour. Each patch shipped as a TYPO3-side workaround. The Masterminds repository has accepted neither.\n\n## The CVE record names the whitespace bypass. The patch closed a second one.\n\nThe same commit, `bd1a88d`, adds a second mitigation that the CVE description does not mention. Twenty-two lines in `src/Serializer/Rules.php`:\n\n```diff\n- if (!$this->isRawText($parentDomNode) || !$this->shallAllowInsecureRawText($parentDomNode)) {\n+ if (!$this->shallAllowInsecureRawText($parentDomNode)) {\n $this->wr($this->enc($domNode->data));\n return;\n }\n@@ -200,6 +199,10 @@\n if ($domNode === null || !$this->behavior instanceof Behavior || !$this->isRawText($domNode)) {\n return false;\n }\n+ // allowing raw-text in elements nested in ``. The serializer, asked to allow insecure raw text in style, writes those bytes back. The output is byte-identical to the input.\n\nA browser receiving that output, with scripting enabled, parses noscript as raw text. The `