|
49 | 49 | import static apoc.util.BinaryTestUtil.fileToBinary;
|
50 | 50 | import static apoc.util.MapUtil.map;
|
51 | 51 | import static apoc.util.TestUtil.isRunningInCI;
|
| 52 | +import static apoc.util.TestUtil.testResult; |
52 | 53 | import static org.junit.Assert.assertEquals;
|
53 | 54 | import static org.junit.Assert.assertFalse;
|
54 | 55 | import static org.junit.Assert.assertNotNull;
|
55 | 56 | import static org.junit.Assert.assertNull;
|
| 57 | +import static org.junit.Assert.assertThrows; |
56 | 58 | import static org.junit.Assert.assertTrue;
|
57 | 59 | import static org.junit.Assume.assumeFalse;
|
58 | 60 | import static org.neo4j.configuration.GraphDatabaseSettings.TransactionStateMemoryAllocation.OFF_HEAP;
|
@@ -714,6 +716,34 @@ public void testExportGraphmlQueryWithStringCaptionCamelCase() {
|
714 | 716 | assertXMLEquals(output, EXPECTED_TYPES_PATH_CAMEL_CASE);
|
715 | 717 | }
|
716 | 718 |
|
| 719 | + @Test |
| 720 | + public void testImportGraphmlPreventXXEVulnerabilityThrowsQueryExecutionException() { |
| 721 | + QueryExecutionException e = assertThrows(QueryExecutionException.class, |
| 722 | + () -> testResult(db, "CALL apoc.import.graphml('" + TestUtil.getUrlFileName("xml/xxe.xml") + "', {})", (r) -> { |
| 723 | + r.next(); |
| 724 | + r.close(); |
| 725 | + }) |
| 726 | + ); |
| 727 | + |
| 728 | + Throwable except = ExceptionUtils.getRootCause(e); |
| 729 | + assertTrue(except instanceof RuntimeException); |
| 730 | + assertEquals(except.getMessage(), "XML documents with a DOCTYPE are not allowed."); |
| 731 | + } |
| 732 | + |
| 733 | + @Test |
| 734 | + public void testImportGraphmlPreventBillionLaughVulnerabilityThrowsQueryExecutionException() { |
| 735 | + QueryExecutionException e = assertThrows(QueryExecutionException.class, |
| 736 | + () -> testResult(db, "CALL apoc.import.graphml('" + TestUtil.getUrlFileName("xml/billion_laughs.xml") + "', {})", (r) -> { |
| 737 | + r.next(); |
| 738 | + r.close(); |
| 739 | + }) |
| 740 | + ); |
| 741 | + |
| 742 | + Throwable except = ExceptionUtils.getRootCause(e); |
| 743 | + assertTrue(except instanceof RuntimeException); |
| 744 | + assertEquals(except.getMessage(), "XML documents with a DOCTYPE are not allowed."); |
| 745 | + } |
| 746 | + |
717 | 747 | private void assertResults(File output, Map<String, Object> r, final String source) {
|
718 | 748 | assertCommons(r);
|
719 | 749 | assertEquals(output.getAbsolutePath(), r.get("file"));
|
|
0 commit comments