//nefariousplan

CVE-2026-47345: TYPO3 html-sanitizer Hardened `enc()`. Its Parent Class Had A Second Writer.

vendor

patterns

cve

proof of concept

TYPO3's html-sanitizer extends Masterminds HTML5's OutputRules and, in the first commit that introduces a subclass at all, overrides one method with care: enc(), the function that turns < into &lt; before the serializer hands a string to the output stream. The override is in src/Serializer/Rules.php, committed 2022-11-28 by Oliver Hader, with a 13-line comment explaining why htmlspecialchars() is being substituted for the parent's htmlentities(). The same parent class ships a second writer, namespaceAttrs(), that does not call enc() at all. CVE-2026-47345, disclosed 2026-06-08 by Doyensec in collaboration with Claude and Anthropic Research, is what happens between the day a sanitizer hardens its encoder and the day someone notices the sister method that never called it. The gap is three years and five months. The CVE record says the namespace attributes were "not encoded correctly during HTML serialization." Read against the code, the verb is wrong. The namespace attributes were not encoded.

The sanitizer extends a parser. The parser has two attribute writers.

The html-sanitizer's job is XSS safety. To get there, it does not write its own HTML5 serializer. It extends Masterminds\HTML5\Serializer\OutputRules, the part of the masterminds/html5 library that walks a parsed DOM tree and emits HTML5-conformant output. OutputRules is in the dependency tree of every TYPO3 installation from 10.4 through 14.3, by way of typo3/html-sanitizer.

OutputRules ships two methods that write name="value" attribute pairs onto the output stream. One is attrs(), for regular HTML attributes. The other is namespaceAttrs(), for XML namespace declarations like xmlns:x="...".

attrs() encodes its values:

protected function attrs($ele)
{
    // FIXME: Needs support for xml, xmlns, xlink, and namespaced elements.
    if (!$ele->hasAttributes()) {
        return $this;
    }
    $map = $ele->attributes;
    $len = $map->length;
    for ($i = 0; $i < $len; ++$i) {
        $node = $map->item($i);
        $val = $this->enc($node->value, true);
        // ...
        $this->wr(' ')->wr($name);
        if ((isset($val) && '' !== $val) || $this->nonBooleanAttribute($node)) {
            $this->wr('="')->wr($val)->wr('"');
        }
    }
}

$this->enc($node->value, true) is the line that turns a literal " in the attribute value into &quot; before it reaches the stream.

namespaceAttrs(), in the same file, does not:

protected function namespaceAttrs($ele)
{
    if (!$this->xpath || $this->xpath->document !== $ele->ownerDocument) {
        $this->xpath = new \DOMXPath($ele->ownerDocument);
    }

    foreach ($this->xpath->query('namespace::*[not(.=../../namespace::*)]', $ele) as $nsNode) {
        if (!in_array($nsNode->nodeValue, $this->implicitNamespaces)) {
            $this->wr(' ')->wr($nsNode->nodeName)->wr('="')->wr($nsNode->nodeValue)->wr('"');
        }
    }
}

$this->wr($nsNode->nodeValue). No enc(). The decoded value travels to the output stream as-is.

Masterminds writes parsers and serializers, not sanitizers. The library's contract is HTML5 conformance, and namespaceAttrs() produces conformant HTML5 even when its value contains a literal >. The browser will parse that output differently than the sanitizer intended, but the bytes are valid. The FIXME comment at the top of attrs() (// FIXME: Needs support for xml, xmlns, xlink, and namespaced elements.) tells you the library knows the two writers diverge on namespaced output. It does not promise the divergence is safe.

The sanitizer overrode the encoder. It did not override the sister writer.

When TYPO3 introduced src/Serializer/Rules.php on 2022-11-28 (commit 703dded, [!!!][FEATURE] Allow to use custom output rules), the author identified enc() as the safety primitive worth hardening. The override is 20 lines and arrives with a comment that names the choice explicitly:

protected function enc($text, $attribute = false): string
{
    if ($attribute && $this->encodeAttributes && !$this->encode) {
        // In contrast to parent::enc() (when $this->encode is true),
        // we are using htmlspecialchars() instead of htmlentities() as
        // colons and slashes do not need to be aggressively escaped.
        $value = htmlspecialchars(
            $text,
            ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES,
            'UTF-8',
            // ...
            true
        );
        return $value;
    }
    return parent::enc($text, $attribute);
}

The override reaches past parent::enc() to install a strictly typed htmlspecialchars() call. The comment names UTF-8 substitution, named entity policy, and the disable-automagic flag. The author understood that enc() was the safety primitive, and that the parent class's encoder was not the encoder the sanitizer wanted.

The same file does not override namespaceAttrs(). The list of methods marked #[\Override] in Rules.php is short and intentional: text(), enc(), resolveNodeName(), shallAllowInsecureRawText(), isRawText(), isVoid(). That list is the threat model. namespaceAttrs() is not on it.

So for the three years and five months between the introduction of the Rules subclass and 2026-04-27, every xmlns:* declaration the sanitizer saw was written to the output by the parent class's unmodified namespaceAttrs(). The carefully hardened encoder lived next door. The sister writer never called it.

The PoC is the test case the patch shipped with itself.

There is no separate PoC repository for CVE-2026-47345. The patch commit, 8b5d0be, adds five lines to tests/CommonBuilderTest.php under generator key #950:

yield '#950' => [
    '<div xmlns:x="&quot;&gt;&lt;img src=x onerror=alert(document.domain)&gt;">text</div>',
    '<div xmlns:x="&quot;&gt;&lt;img src=x onerror=alert(document.domain)&gt;">text</div>',
];

The first string is the input. The second string is the expected output after sanitization. Before the patch, the assertion failed because the output was not the second string. It was this:

<div xmlns:x=""><img src=x onerror=alert(document.domain)>">text</div>

Walk through it. The HTML5 parser sees xmlns:x="&quot;&gt;&lt;img src=x onerror=alert(document.domain)&gt;". It decodes the entities and stores the decoded form on the DOM node as the namespace value: "><img src=x onerror=alert(document.domain)>. The sanitizer's visitor pipeline runs. The xmlns:x namespace declaration is not on any deny list because CommonBuilder does not filter namespace declarations. The serializer reaches the element, calls namespaceAttrs() on the parent class, and emits:

 xmlns:x="

then $this->wr($nsNode->nodeValue), which writes the decoded value verbatim. The decoded value is "><img src=x onerror=alert(document.domain)>. The first byte is ", which closes the attribute the writer just opened. The next bytes are HTML the browser parses as a new element. The <img> enters the DOM. The onerror handler fires. The sanitizer's output, fed into a page that trusted it to be safe, executes attacker-supplied JavaScript in the context of the document the user is reading.

The encoder that would have turned that " into &quot; exists in the same file. The sanitizer hardened it on day one. namespaceAttrs() did not reach for it.

The patch is one method.

src/Serializer/Rules.php after the patch:

+    /**
+     * Write the namespace attributes.
+     *
+     * @param \DOMNode $ele The element being written.
+     */
+    #[\Override]
+    protected function namespaceAttrs($ele)
+    {
+        $xpath = new \DOMXPath($ele->ownerDocument);
+
+        foreach ($xpath->query('namespace::*[not(.=../../namespace::*)]', $ele) as $nsNode) {
+            if (!in_array($nsNode->nodeValue, $this->implicitNamespaces)) {
+                $this->wr(' ')->wr($nsNode->nodeName)->wr('="')->wr($this->enc($nsNode->nodeValue, true))->wr('"');
+            }
+        }
+    }

Seventeen lines. The XPath query is the parent class's XPath query. The implicitNamespaces filter is the parent class's filter. The $this->wr(' ')->wr($nsNode->nodeName)->wr('="') prefix is the parent class's prefix. The single mechanical change is the value write: $this->wr($this->enc($nsNode->nodeValue, true)) in place of $this->wr($nsNode->nodeValue). One function call. The function is the override the sanitizer added in 2022.

The fix is one method override marked #[\Override], added to the list of methods that needed overriding. The list grew by one.

The library hands you a class. The unsafe sinks stay in the parent.

This is extension-as-mitigation. The library masterminds/html5 exposes OutputRules as a subclass-able extension point and tells the consumer, via the [!!!][FEATURE] commit that introduced the seam in typo3/html-sanitizer itself, that the way to customize serializer behavior is to subclass it. The TYPO3 sanitizer authors took the seam. They identified the methods whose behavior they needed to change for safety, and overrode those. The list lives in src/Serializer/Rules.php, every method tagged #[\Override]. The list looks complete.

It was not. Masterminds does not enumerate which methods in OutputRules need to be safe-overridden when the class is used as a sanitizer base. Masterminds does not promise that any method in OutputRules is safe for that purpose. The contract is HTML5 conformance. The unsafe sinks remain in the parent class, unchanged, because no one wrote them down as "these need overriding for safety." The patch closes one. The next sibling method the override list does not name is the next CVE.

The same component shipped a second CVE the same day. TYPO3-CORE-SA-2026-006 assigned CVE-2026-47344 against the same typo3/html-sanitizer versions, by the same researchers (IPC Labs and Doyensec, with Anthropic Research). CVE-2026-47344 is a browser-parser differential: when ALLOW_INSECURE_RAW_TEXT is set on a tag, the sanitizer's tokenizer accepts </style> as the closing tag but does not accept </style\t>. The browser does. The fix is a custom Tokenizer subclass that overrides Masterminds' rawText(), plus a guard in Rules.php that denies raw-text passthrough inside <noscript>. Two more subclasses. Two more methods now on the override list.

The two CVEs are not the same bug. They are the same shape. Six prior [SECURITY] commits in this repository have the same shape too. Each disclosure cycle in typo3/html-sanitizer identifies one or two more methods or tokenizer states the sanitizer should have overridden and did not. The fix on each is small. This is the Design Debt Driver the component carries forward: every patch adds one method to the override list, and the override list is a subset of the parent class.

What the disclosure credit names.

The TYPO3 advisory credits "IPC Labs and Doyensec (in collaboration with Claude and Anthropic Research)." This is the second sanitizer-bypass advisory in two months whose researcher line names an AI vendor as a research collaborator. The class of bug it found is the kind that is found by pattern-aware code reading: two parallel functions in the same parent class, one calling the encoder and one not, in a class a downstream library uses as a sanitizer base. An auditor who reads the parent class with that lens finds the bug as soon as they grep for callers of enc() and notice which sibling methods do not appear. The PoC is the test case that the auditor handed to the maintainer along with the fix.

The mechanism is the same mechanism that has been in OutputRules since OutputRules had a namespaceAttrs method. The lens is the new thing.

The CVE record says the namespace attributes were "not encoded correctly during HTML serialization." Read against the code, the verb is wrong. The namespace attributes were not encoded.