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
22 changes: 21 additions & 1 deletion jaxb/src/main/java/feign/jaxb/JAXBDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@

import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;

import feign.Response;
import feign.Util;
import feign.codec.DecodeException;
import feign.codec.Decoder;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* Decodes responses using JAXB. <br> <p> Basic example with with Feign.Builder: </p>
Expand Down Expand Up @@ -57,11 +63,25 @@ public Object decode(Response response, Type type) throws IOException {
throw new UnsupportedOperationException(
"JAXB only supports decoding raw types. Found " + type);
}


try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
/* Explicitly control sax configuration to prevent XXE attacks */
saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
saxParserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
saxParserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

Source source = new SAXSource(saxParserFactory.newSAXParser().getXMLReader(), new InputSource(response.body().asInputStream()));
Unmarshaller unmarshaller = jaxbContextFactory.createUnmarshaller((Class) type);
return unmarshaller.unmarshal(response.body().asInputStream());
return unmarshaller.unmarshal(source);
} catch (JAXBException e) {
throw new DecodeException(e.toString(), e);
} catch (ParserConfigurationException e) {
throw new DecodeException(e.toString(), e);
} catch (SAXException e) {
throw new DecodeException(e.toString(), e);
} finally {
if (response.body() != null) {
response.body().close();
Expand Down
5 changes: 5 additions & 0 deletions sax/src/main/java/feign/sax/SAXDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public Object decode(Response response, Type type) throws IOException, DecodeExc
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
xmlReader.setFeature("http://xml.org/sax/features/validation", false);
/* Explicitly control sax configuration to prevent XXE attacks */
xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
xmlReader.setContentHandler(handler);
InputStream inputStream = response.body().asInputStream();
try {
Expand Down