TYPO3's html-sanitizer 2.3.2 introduces a Tokenizer subclass whose entire reason for existing is to override one method, rawText(), on Masterminds\HTML5\Parser\Tokenizer. The override is forty lines. Its docblock says it exists to match "the behaviour of rcdata() and the HTML5 spec (§ 8.2.6.1)." Masterminds\HTML5\Parser\Tokenizer::rcdata() has matched § 8.2.6.1 since Zhaofeng Li's commit 7c1c7dfa on 2015-02-02. Its sibling rawText() in the same file did not, for the next four thousand one hundred and two days. CVE-2026-47344 is what shipped through the divergent method to every consumer of Masterminds that does not subclass the parser.
CVE-2026-47344: Masterminds' rcdata() Accepted Whitespace In 2015. rawText() Did Not, For 4,102 Days.
vendor
patterns
cve
proof of concept
The fix lives in TYPO3's repository, not in Masterminds'
Oliver Hader's commit bd1a88d on 2026-04-27 adds two new files to typo3/html-sanitizer:
src/Parser/Html5.php, a sixty-five-line subclass ofMasterminds\HTML5whose only purpose is to instantiate the local Tokenizer instead of the upstream one.src/Parser/Tokenizer.php, a sixty-nine-line subclass ofMasterminds\HTML5\Parser\Tokenizerwhose only purpose is to overriderawText().
Then it rewires Sanitizer::createParser():
-use Masterminds\HTML5;
+use TYPO3\HtmlSanitizer\Parser\Html5;
- protected function createParser(): HTML5
+ protected function createParser(): Html5
{
- return new HTML5(self::mastermindsDefaultOptions);
+ return new Html5(self::mastermindsDefaultOptions);
}Nothing 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:
/**
* Extends the Masterminds tokenizer to fix rawText() so that it recognises
* whitespace-variant closing tags (e.g. </style\t>) as valid end tags per
* HTML5 spec § 8.2.6.1, aligning it with the existing rcdata() behaviour.
*/
class Tokenizer extends MastermindsTokenizer"Aligning it with the existing rcdata() behaviour." The existing behaviour is the sibling method in the same class the TYPO3 maintainer cannot reach.
rcdata() and rawText() are twenty lines apart in the same file
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 >.
rawText(), in the version that shipped from 2014-06-11 until today:
protected function rawText($tok)
{
if (is_null($this->untilTag)) {
return $this->text($tok);
}
$sequence = '</' . $this->untilTag . '>';
$txt = $this->readUntilSequence($sequence);
$this->events->text($txt);
$this->setTextMode(0);
return $this->endTag();
}$sequence is constructed with a literal trailing >. readUntilSequence() is a byte-for-byte scan. If the input contains </style\t> and no later </style>, the scan walks to EOF and returns the entire rest of the stream as text content.
rcdata(), six lines below:
protected function rcdata($tok)
{
if (is_null($this->untilTag)) {
return $this->text($tok);
}
$sequence = '</' . $this->untilTag;
$txt = '';
$caseSensitive = !Elements::isHtml5Element($this->untilTag);
while (false !== $tok && !('<' == $tok && ($this->scanner->sequenceMatches($sequence, $caseSensitive)))) {
if ('&' == $tok) {
$txt .= $this->decodeCharacterReference();
$tok = $this->scanner->current();
} else {
$txt .= $tok;
$tok = $this->scanner->next();
}
}
$len = strlen($sequence);
$this->scanner->consume($len);
$len += $this->scanner->whitespace();
if ('>' !== $this->scanner->current()) {
$this->parseError('Unclosed RCDATA end tag');
}
$this->scanner->unconsume($len);
$this->events->text($txt);
$this->setTextMode(0);
return $this->endTag();
}$sequence is constructed without the trailing >. The loop stops as soon as </tagname appears. After the loop, the scanner consumes the matched length, then consumes any whitespace, then asserts the next byte is >. Whitespace between the tag name and > is part of the contract.
The 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.
The browser stops at the whitespace
HTML5 § 8.2.6.1, "Tokenization", specifies the end-tag-open state: after </, the tokenizer reads the tag name until it hits whitespace, /, or >. 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.
The Masterminds rawText() reads it as continuing raw text. The PoC the patch's regression test ships exercises the exact differential:
<style>div::after{content:'<'}</style ><img src=x onerror=alert(1)>Pre-patch, with a Behavior declaring style as ALLOW_CHILDREN | ALLOW_INSECURE_RAW_TEXT, the sanitizer's tree builder sees one style element whose text content is div::after{content:'<'}</style\t><img src=x onerror=alert(1)>. The serializer, asked to allow insecure raw text in style, writes those bytes through unchanged. The output the sanitizer emits is byte-for-byte the input.
The browser receiving that output parses </style\t> as the end-of-style token, exits raw text mode, parses <img src=x onerror=alert(1)> as an image element, and fires the handler.
Post-patch, the regression test for this scenario captures the alignment:
yield 'style whitespace closing tag is recognized (img is removed - insecure raw text allowed)' => [
[$styleInsecureRawText],
"<style>div::after{content:'<'}</style\t><img src=x onerror=alert(1)>",
'<style>div::after{content:\'<\'}</style>',
];The TYPO3 tokenizer now exits raw text at </style\t>. 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.
rcdata() got the fix on 2015-02-02. rawText() did not.
git blame on Masterminds' Tokenizer.php:
e49c4591 (Asmir Mustafic 2014-06-11) protected function rawText($tok)
e49c4591 (Asmir Mustafic 2014-06-11) {
e49c4591 (Asmir Mustafic 2014-06-11) if (is_null($this->untilTag)) {
e49c4591 (Asmir Mustafic 2014-06-11) return $this->text($tok);
e49c4591 (Asmir Mustafic 2014-06-11) }
e49c4591 (Asmir Mustafic 2014-06-11) $sequence = '</' . $this->untilTag . '>';
e49c4591 (Asmir Mustafic 2014-06-11) $txt = $this->readUntilSequence($sequence);The '</' . $this->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.
Eight months later, on 2015-02-02, Zhaofeng Li committed 7c1c7dfa, title "Allow whitespaces in RCDATA end tags," closing Masterminds issue #75:
- $sequence = '</' . $this->untilTag . '>';
- $txt = $this->readUntilSequence($sequence);
+ $sequence = '</' . $this->untilTag;
+ $txt = '';
+
+ while (false !== $tok && !('<' == $tok && ($this->scanner->sequenceMatches($sequence, false)))) {
+ ...
+ }
+ $len = strlen($sequence);
+ $this->scanner->consume($len);
+ $len += $this->scanner->whitespace();
+ if ('>' !== $this->scanner->current()) {
+ ...
+ }The 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.
Between 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.
This is the 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.
TYPO3 fixed it downstream because nobody fixed it upstream
The 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.
The 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.
The 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 >.
This is 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.
The CVE record names the whitespace bypass. The patch closed a second one.
The same commit, bd1a88d, adds a second mitigation that the CVE description does not mention. Twenty-two lines in src/Serializer/Rules.php:
- if (!$this->isRawText($parentDomNode) || !$this->shallAllowInsecureRawText($parentDomNode)) {
+ if (!$this->shallAllowInsecureRawText($parentDomNode)) {
$this->wr($this->enc($domNode->data));
return;
}
@@ -200,6 +199,10 @@
if ($domNode === null || !$this->behavior instanceof Behavior || !$this->isRawText($domNode)) {
return false;
}
+ // allowing raw-text in elements nested in `<noscript>` is denied per default
+ if ($this->hasAncestorWithName($domNode, 'noscript')) {
+ return false;
+ }shallAllowInsecureRawText() now returns false for any node whose ancestor chain contains <noscript>, regardless of the Behavior flag the operator set on the immediate tag. The commit message names what the CVE description does not:
"Deny raw text passthrough inside
<noscript>, where browsers with JavaScript enabled parse the content as raw text, making inner closing tags invisible and allowing payloads to escape the raw text context."
HTML5 specifies noscript as a dual-mode element. With scripting disabled (Masterminds, headless parsers, server-side renderers), the contents are parsed as ordinary HTML. With scripting enabled (every consumer browser that runs JavaScript), the contents are parsed as raw text up to the literal </noscript> token. The two parsers build different DOMs from the same byte stream by spec.
The regression test the patch adds:
yield 'noscript nesting another raw-text element is denied (content is encoded - insecure raw text allowed)' => [
[$noscript, $styleInsecureRawText],
'<noscript><style></noscript><img src=x onerror=alert(2)></style></noscript>',
'<noscript><style></noscript><img src=x onerror=alert(2)></style></noscript>',
];Pre-patch, with style declared as ALLOW_INSECURE_RAW_TEXT and noscript as a permitted ancestor, the sanitizer's parser, running without scripting, sees:
noscript
└── style
└── text: "</noscript><img src=x onerror=alert(2)>"The style element's text content is the literal string </noscript><img src=x onerror=alert(2)>. The serializer, asked to allow insecure raw text in style, writes those bytes back. The output is byte-identical to the input.
A browser receiving that output, with scripting enabled, parses noscript as raw text. The <style> literal is text inside noscript. The first </noscript> ends noscript. The <img src=x onerror=alert(2)> is a real DOM element. The handler fires. The browser never instantiated a style element; it parsed an img.
The sanitizer's tree builder and the consumer browser's tree builder are not modelling the same noscript. They cannot, because the spec defines noscript's content model conditional on a runtime state (scripting on/off) the server-side parser has no access to. The fix denies the insecure flag inside noscript universally because the sanitizer cannot know which parser is downstream and the wrong choice is unrecoverable.
The CVE description, in NVD and on cve.org, names only the whitespace-variant closing tag. The commit message names two mitigations. The patch ships both. This is the pattern we covered three days ago in inetutils-telnetd: the affected-products field reflects what the public PoC demonstrated, not what the patch closed.
The opt-in flag the 2022 patch added is what the 2026 patch had to defend
ALLOW_INSECURE_RAW_TEXT was introduced in the 2022-12-13 commit that closed CVE-2022-23499. It exists because some legitimate consumers of the html-sanitizer need to ship style sheets, script blocks, or iframes through to output without HTML-encoding their contents. The flag's name is the author labelling the unsafe path in the API.
The 2026 patch's two mitigations are both qualifications on that flag:
- Even when the flag is set, the underlying tokenizer must agree with the browser about where the element ends.
- Even when the flag is set, the element must not be nested in a noscript whose dual-mode parsing the server-side tokenizer cannot model.
Both qualifications are now enforced inside the library. Neither was enforced when the flag shipped in 2022. The flag's API surface advertised "insecure raw text"; the runtime delivered "insecure raw text under the assumption the upstream tokenizer's end-tag detection matches the browser's." That assumption was wrong for eleven years.
PoC: GHSA-jvf5-rxvv-3mcg.
The TYPO3 subclass override is forty lines. The upstream method it shadows is twelve. The difference between them is four thousand one hundred and two days.