Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ java-приложение для работы с блокировками в С

* Обновлена лицензия
* Обновлены библиотеки
* Исправлена уязвимость при чтении XML

1.9.0

Expand Down
20 changes: 18 additions & 2 deletions src/main/java/ru/taximaxim/pgsqlblocks/xmlstore/XmlStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
Expand Down Expand Up @@ -116,8 +117,23 @@ public void writeObjects(List<T> list) {
*/
private Document readXml(Reader reader) throws IOException, SAXException {
try {
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new InputSource(reader));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Disable DOCTYPE declarations entirely
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// Disable external general entities
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
// Disable external parameter entities
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
// Disable loading external DTDs
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
// Disabling XInclude
factory.setXIncludeAware(false);
// Disable entity expansion (protection against Billion Laughs)
factory.setExpandEntityReferences(false);
// Prohibit the use of all protocols by external entities (JAXP 1.5+)
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
Document xml = factory.newDocumentBuilder().parse(new InputSource(reader));
xml.normalize();

if (!xml.getDocumentElement().getNodeName().equals(rootTag)) {
Expand Down
Loading