-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set FEATURE_SECURE_PROCESSING for DocumentBuilderFactory
- Loading branch information
1 parent
31fe8bf
commit 37da4ec
Showing
2 changed files
with
18 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,16 @@ | |
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.XMLConstants; | ||
import javax.xml.bind.DatatypeConverter; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Class that's initially a placeholder for XMP specific functionality. | ||
|
@@ -51,6 +54,7 @@ | |
* @author <a href="mailto:[email protected]">Carl Wilson</a> | ||
*/ | ||
public class XmpHandler { | ||
private static final Logger LOGGER = Logger.getLogger(XmpHandler.class.getCanonicalName()); | ||
private static final byte[] UTF8_METADATA_PREFIX_SQ = {0x3C, 0x3F, 0x78, | ||
0x70, 0x61, 0x63, 0x6B, 0x65, 0x74, 0x20, 0x62, 0x65, 0x67, 0x69, | ||
0x6E, 0x3D, 0x27, -0x11, -0x45, -0x41, 0x27}; | ||
|
@@ -134,6 +138,11 @@ public static Node parseMetadataRootElement(FeatureTreeNode metadataNode) | |
return null; | ||
} | ||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
try { | ||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); | ||
} catch (Exception e) { | ||
LOGGER.log(Level.WARNING, "Unable to secure metadata processing"); | ||
} | ||
factory.setNamespaceAware(true); | ||
DocumentBuilder builder = factory.newDocumentBuilder(); | ||
Document metadataDocument = builder.parse(is); | ||
|