Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/bootstrap/src/org/labkey/bootstrap/ModuleArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import javax.xml.XMLConstants;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
Expand Down Expand Up @@ -71,7 +72,14 @@ private String nameFromModuleXML(InputStream is) throws IOException

try
{
SAXParser parser = SAXParserFactory.newDefaultInstance().newSAXParser();
// Keep this in sync with config on XmlBeansUtil.SAX_PARSER_FACTORY. See motiviations in comments there.
SAXParserFactory factory = SAXParserFactory.newDefaultInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this blog post I found from 2012 these settings seem to be mutually exclusive. My understanding is that you need to either disable doctype declaration (what this line does) or disable external entities (what the following two lines do). I'm not sure it's problematic to do both though, so maybe we should keep it.

https://blog.compass-security.com/2012/08/secure-xml-parser-configuration/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be safe to do both, just in case.

factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

SAXParser parser = factory.newSAXParser();
parser.parse(is, new DefaultHandler()
{
final ArrayList<String> elementStack = new ArrayList<>();
Expand Down