Menu ▾ ▴

#170 NekoHTML 1.9.22: Uncaught DOMException Triggered by Unsupported XML Declaration Version

1.9.15
open
nobody
None
5
2026-10-29
2026-10-29
Wang xinxin
No

Summary

NekoHTML 1.9.22 throws an uncaught DOMException: NOT_SUPPORTED_ERR when parsing an HTML document beginning with an XML declaration whose version is not 1.0 or 1.1.

The exception propagates from Xerces through NekoHTML's XML declaration handling path and escapes DOMParser.parse().

The issue is reproducible under the default parser configuration, using a minimal input:

<?xml version="2.0"?>

Applications processing attacker-controlled HTML may experience request failures or interrupted document-processing jobs if this unchecked exception is not handled.

Environment

  • Artifact: net.sourceforge.nekohtml:nekohtml
  • Latest tested version: 1.9.22
  • Xerces dependency: 2.11.0
  • JDK: 17
  • OS: Linux
  • Potential weakness: CWE-248 (Uncaught Exception)

Steps to Reproduce

Using NekoHTML 1.9.22, execute the following Java program:

import java.io.StringReader;
import org.cyberneko.html.parsers.DOMParser;
import org.xml.sax.InputSource;

public class Repro {
    public static void main(String[] args) throws Exception {
        new DOMParser().parse(
            new InputSource(
                new StringReader("<?xml version=\"2.0\"?>")
            )
        );
    }
}

Actual Result

The parser throws an unchecked exception:

org.w3c.dom.DOMException: NOT_SUPPORTED_ERR:
The implementation does not support the requested type of object or operation.
    at org.apache.xerces.dom.CoreDocumentImpl.setXmlVersion(Unknown Source)
    at org.apache.xerces.parsers.AbstractDOMParser.xmlDecl(Unknown Source)
    at org.cyberneko.html.HTMLTagBalancer.xmlDecl(HTMLTagBalancer.java:445)
    at org.cyberneko.html.filters.DefaultFilter.xmlDecl(DefaultFilter.java:104)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scanPI(HTMLScanner.java:2660)
    at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2090)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)

Expected Result

Malformed or unsupported XML declaration versions should be handled gracefully.

When parsing HTML input, an unsupported XML version should not cause an unchecked DOMException to escape the parser API. The parser should recover appropriately or report a controlled parsing error.

Affected Version Matrix

NekoHTML Xerces Result
1.9.12 2.8.1 Reproduced
1.9.16 2.9.1 Reproduced
1.9.20 2.10.0 Reproduced
1.9.21 2.10.0 Reproduced
1.9.22 2.11.0 Reproduced

Other versions were not tested.

Trigger Matrix

Input Result
<?xml version="1.0"?> Parses successfully
<?xml version="1.1"?> Parses successfully
<?xml version="2.0"?> Throws DOMException
<?xml version=1.1?> Throws DOMException
Malformed XML declaration with an unclosed version value Throws DOMException

The same inputs were processed without this exception by jsoup 1.23.2, validator.nu HTML Parser 1.4.16, and TagSoup 1.2.1.

Root Cause

NekoHTML forwards the XML declaration version to Xerces without validating whether the value is supported.

The relevant call path is:

HTMLScanner.scanPI() → HTMLTagBalancer.xmlDecl() → AbstractDOMParser.xmlDecl() → CoreDocumentImpl.setXmlVersion()

Xerces supports XML versions 1.0 and 1.1. Unsupported values cause setXmlVersion() to throw a DOMException, which propagates through NekoHTML's parsing API.

Potential Security Impact

An attacker who can supply HTML content to an application using NekoHTML may trigger an uncaught runtime exception during parsing.

If the consuming application does not properly handle such exceptions, the affected request or document-processing job may fail.

This represents a potential context-dependent denial-of-service condition.

The current proof of concept demonstrates termination of an individual parsing operation. It does not establish JVM termination, persistent service unavailability, or resource exhaustion.

Suggested Fix

Validate the XML declaration version before forwarding it to Xerces.

Unsupported or malformed version values should be handled as controlled parsing errors or ignored according to the parser's HTML recovery semantics, rather than allowing a DOMException to escape.

Regression tests should cover supported, unsupported, unquoted, and malformed XML version values.

Discussion


Log in to post a comment.