Merge pull request from GHSA-r2hc-pmr7-4c9r
* Configured XML parsers to resist XXE attacks Signed-off-by: Kai Kreuzer <kai@openhab.org> * added fix for avmfritz Signed-off-by: Kai Kreuzer <kai@openhab.org> * added fix for sonos Signed-off-by: Kai Kreuzer <kai@openhab.org> * added fix for vitotronic and bosesoundtouch Signed-off-by: Kai Kreuzer <kai@openhab.org> * changed avmfritz to singleton pattern Signed-off-by: Kai Kreuzer <kai@openhab.org> * addressed roku binding Signed-off-by: Kai Kreuzer <kai@openhab.org> * address all uses of DocumentBuilderFactory Signed-off-by: Kai Kreuzer <kai@openhab.org> * fixed other occurrences in roku binding Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
@@ -18,6 +18,8 @@ import java.io.StringReader;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.avmfritz.internal.dto.DeviceListModel;
|
||||
@@ -62,15 +64,16 @@ public class FritzAhaUpdateCallback extends FritzAhaReauthCallback {
|
||||
logger.trace("Received State response {}", response);
|
||||
if (isValidRequest()) {
|
||||
try {
|
||||
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
|
||||
Unmarshaller unmarshaller = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
|
||||
DeviceListModel model = (DeviceListModel) unmarshaller.unmarshal(new StringReader(response));
|
||||
DeviceListModel model = (DeviceListModel) unmarshaller.unmarshal(xsr);
|
||||
if (model != null) {
|
||||
handler.onDeviceListAdded(model.getDevicelist());
|
||||
} else {
|
||||
logger.debug("no model in response");
|
||||
}
|
||||
handler.setStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
|
||||
} catch (JAXBException e) {
|
||||
} catch (JAXBException | XMLStreamException e) {
|
||||
logger.error("Exception creating Unmarshaller: {}", e.getLocalizedMessage(), e);
|
||||
handler.setStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||
e.getLocalizedMessage());
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.io.StringReader;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.avmfritz.internal.dto.templates.TemplateListModel;
|
||||
@@ -58,14 +60,15 @@ public class FritzAhaUpdateTemplatesCallback extends FritzAhaReauthCallback {
|
||||
logger.trace("Received response '{}'", response);
|
||||
if (isValidRequest()) {
|
||||
try {
|
||||
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
|
||||
Unmarshaller unmarshaller = JAXBUtils.JAXBCONTEXT_TEMPLATES.createUnmarshaller();
|
||||
TemplateListModel model = (TemplateListModel) unmarshaller.unmarshal(new StringReader(response));
|
||||
TemplateListModel model = (TemplateListModel) unmarshaller.unmarshal(xsr);
|
||||
if (model != null) {
|
||||
handler.addTemplateList(model.getTemplates());
|
||||
} else {
|
||||
logger.debug("no template in response");
|
||||
}
|
||||
} catch (JAXBException e) {
|
||||
} catch (JAXBException | XMLStreamException e) {
|
||||
logger.error("Exception creating Unmarshaller: {}", e.getLocalizedMessage(), e);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,7 @@ package org.openhab.binding.avmfritz.internal.util;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@@ -34,6 +35,7 @@ public class JAXBUtils {
|
||||
|
||||
public static final @Nullable JAXBContext JAXBCONTEXT_DEVICES = initJAXBContextDevices();
|
||||
public static final @Nullable JAXBContext JAXBCONTEXT_TEMPLATES = initJAXBContextTemplates();
|
||||
public static final XMLInputFactory XMLINPUTFACTORY = initXMLInputFactory();
|
||||
|
||||
private static @Nullable JAXBContext initJAXBContextDevices() {
|
||||
try {
|
||||
@@ -52,4 +54,11 @@ public class JAXBUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static XMLInputFactory initXMLInputFactory() {
|
||||
XMLInputFactory xif = XMLInputFactory.newInstance();
|
||||
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
|
||||
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
||||
return xif;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user