-
Notifications
You must be signed in to change notification settings - Fork 72
Prevent XML xxe on Strict HL7 parsing #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.mirth.connect.plugins.datatypes.hl7v2; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
|
|
@@ -15,11 +16,22 @@ | |
|
|
||
| public class ER7SerializerTest { | ||
| private static ER7Serializer serializer; | ||
|
|
||
| private static ER7Serializer strictSerializer; | ||
| private static ER7Serializer strictSerializerAllowXml; | ||
|
|
||
| @BeforeClass | ||
| public static void setupClass() throws Exception { | ||
| SerializerProperties serializerProperties = new SerializerProperties(new HL7v2SerializationProperties(), new HL7v2DeserializationProperties(), null); | ||
| serializer = new ER7Serializer(serializerProperties); | ||
|
|
||
| HL7v2SerializationProperties strictProperties = new HL7v2SerializationProperties(); | ||
| strictProperties.setUseStrictParser(true); | ||
| strictSerializer = new ER7Serializer(new SerializerProperties(strictProperties, new HL7v2DeserializationProperties(), null)); | ||
|
|
||
| HL7v2SerializationProperties strictPropertiesAllowXml = new HL7v2SerializationProperties(); | ||
| strictPropertiesAllowXml.setUseStrictParser(true); | ||
| strictPropertiesAllowXml.setAllowXml(true); | ||
| strictSerializerAllowXml = new ER7Serializer(new SerializerProperties(strictPropertiesAllowXml, new HL7v2DeserializationProperties(), null)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -53,4 +65,27 @@ public void testValidFromXMLWithExternalDTD() throws Exception { | |
|
|
||
| assertFalse(exceptionThrown); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToXmlWithStrictParserRejectsXmlInputByDefault() throws Exception { | ||
| String xmlDisguisedAsHl7 = "<foo><bar>notreallyhl7</bar></foo>"; | ||
|
|
||
| boolean exceptionThrown = false; | ||
| try { | ||
| strictSerializer.toXML(xmlDisguisedAsHl7); | ||
| } catch (MessageSerializerException e) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this specifically inspect the exception message and cause? That way it validates it threw because of the XML parsing and not because of some other serialization fault. What is the output of this test before and after the other code changes? |
||
| exceptionThrown = true; | ||
| } | ||
|
|
||
| assertTrue(exceptionThrown); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToXmlWithStrictParserAllowsXmlInputWhenOptedIn() throws Exception { | ||
| String xmlDisguisedAsHl7 = "<foo><bar>notreallyhl7</bar></foo>"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor this to a constant since its used in multiple tests |
||
|
|
||
| String result = strictSerializerAllowXml.toXML(xmlDisguisedAsHl7); | ||
|
|
||
| assertEquals(xmlDisguisedAsHl7, result); | ||
| } | ||
| } | ||
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.
Non-blocking - How can this be documented in the release notes?