Skip to content

Commit

Permalink
Merge pull request #994 from HL7/do-20241119-checkstyle-for-xml-new-i…
Browse files Browse the repository at this point in the history
…nstances

Automate testing for XMLUtils factory methods
  • Loading branch information
grahamegrieve authored Nov 20, 2024
2 parents 0928587 + 87572bc commit 2fcdd2e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
54 changes: 43 additions & 11 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,49 @@
<module name="TreeWalker">
<!--
<module name="TodoComment">-->
<!-- The (?i) below means Case Insensitive -->
<!-- The (?i) below means Case Insensitive -->
<!--<property name="format" value="(?i)FIXME"/>
-->
<module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.NotNull"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.Nullable"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.\*"/>
</module>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.NotNull"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.Nullable"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="org\.jetbrains\.annotations\.\*"/>
</module>
</module>
<module name="RegexpMultiline">
<property name="id" value="transformerFactoryNewInstance"/>
<property name="matchAcrossLines" value="true"/>
<property name="format" value="TransformerFactory\.newInstance\("/>
<property name="message"
value="Usage of TransformerFactory.newInstance() is only allowed in XMLUtil.newXXEProtectedTransformerFactory()."
/>
</module>
<module name="RegexpMultiline">
<property name="id" value="documentBuilderFactoryNewInstance"/>
<property name="matchAcrossLines" value="true"/>
<property name="format" value="DocumentBuilderFactory\.newInstance\("/>
<property name="message"
value="Usage of DocumentBuilderFactory.newInstance() is only allowed in XMLUtil.newXXEProtectedDocumentBuilderFactory()."
/>
</module>
<module name="RegexpMultiline">
<property name="id" value="saxParserFactoryNewInstance"/>
<property name="matchAcrossLines" value="true"/>
<property name="format" value="SAXParserFactory\.newInstance\("/>
<property name="message"
value="Usage of SAXParserFactory.newInstance() is only allowed in XMLUtil.newXXEProtectedSaxParserFactory()."
/>
</module>
<module name="RegexpMultiline">
<property name="id" value="getXMLReader"/>
<property name="matchAcrossLines" value="true"/>
<property name="format" value="\.getXMLReader\("/>
<property name="message"
value="Usage of SAXParserFactory.getXMLReader() is only allowed in XMLUtil.getXXEProtectedXMLReader(...)."
/>
</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -14312,7 +14312,7 @@ private String fetchCurrentIGPubVersion() {
private void loadMappingSpaces(byte[] source) throws Exception {
ByteArrayInputStream is = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = XMLUtil.newXXEProtectedDocumentBuilderFactory();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
is = new ByteArrayInputStream(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private void check(boolean condition, String message) {

private Document loadXml(File file) throws Exception {
InputStream src = new FileInputStream(file);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dbf = XMLUtil.newXXEProtectedDocumentBuilderFactory();
DocumentBuilder db = dbf.newDocumentBuilder();
return db.parse(src);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ private void check(boolean condition, String message) {

private Document loadXml(File file) throws Exception {
InputStream src = new FileInputStream(file);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dbf = XMLUtil.newXXEProtectedDocumentBuilderFactory();
DocumentBuilder db = dbf.newDocumentBuilder();
return db.parse(src);
}
Expand Down

0 comments on commit 2fcdd2e

Please sign in to comment.