Cannot disable DTDs with PubMed, so instead disallow external entities & entity expansion

(cherry picked from commit f9614c41a6)
This commit is contained in:
Tim Donohue
2025-04-29 16:57:31 -05:00
committed by github-actions[bot]
parent 6fe9af84bd
commit 90ea371e0b

View File

@@ -234,8 +234,10 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
try {
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// Disallow external entities & entity expansion to protect against XXE attacks
// (NOTE: We receive errors if we disable all DTDs for PubMed, so this is the best we can do)
saxBuilder.setFeature("http://xml.org/sax/features/external-general-entities", false);
saxBuilder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
Document document = saxBuilder.build(new StringReader(src));
Element root = document.getRootElement();