44package com .marklogic .client .test .example .extension ;
55
66import com .marklogic .client .example .extension .OpenCSVBatcherExample ;
7+ import com .marklogic .client .impl .XmlFactories ;
78import org .junit .jupiter .api .Test ;
9+ import org .xml .sax .SAXException ;
10+
11+ import javax .xml .parsers .DocumentBuilder ;
12+ import java .io .ByteArrayInputStream ;
13+ import java .nio .charset .StandardCharsets ;
14+
15+ import static org .junit .jupiter .api .Assertions .assertThrows ;
816
917class OpenCSVBatcherTest {
1018
@@ -13,4 +21,20 @@ void testMain() throws Exception {
1321 // This is a simple smoke test to ensure that the main method runs without exceptions.
1422 OpenCSVBatcherExample .main (new String [0 ]);
1523 }
24+
25+ @ Test
26+ void documentBuilderShouldRejectDoctype () throws Exception {
27+ // Verifies that the DocumentBuilder produced by XmlFactories.getDocumentBuilderFactory()
28+ // — the same factory now used by OpenCSVBatcher.write() — rejects DOCTYPE declarations,
29+ // confirming that XXE / DTD processing is disabled (CWE-611).
30+ DocumentBuilder builder = XmlFactories .getDocumentBuilderFactory ().newDocumentBuilder ();
31+ String xmlWithDoctype =
32+ "<?xml version=\" 1.0\" ?>" +
33+ "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \" file:///etc/passwd\" >]>" +
34+ "<foo>&xxe;</foo>" ;
35+
36+ assertThrows (SAXException .class , () ->
37+ builder .parse (new ByteArrayInputStream (xmlWithDoctype .getBytes (StandardCharsets .UTF_8 )))
38+ );
39+ }
1640}
0 commit comments