diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java index dc5d04ae824..2d266aa3127 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java @@ -61,6 +61,26 @@ import org.springframework.util.StreamUtils; * Implementation of {@link org.springframework.http.converter.HttpMessageConverter} * that can read and write {@link Source} objects. * + *
Security considerations: {@link #setSupportDtd supportDtd} + * and {@link #setProcessExternalEntities processExternalEntities} only apply + * when reading a request body into a {@code DOMSource}, + * {@code SAXSource} or {@code StAXSource}. They do not apply to writing. + * Spring Framework trusts the application and its data sources, so the XML being written + * is assumed to be application-controlled. Only reading untrusted XML is + * protected against XXE. + * + *
When a handler declares a {@code StreamSource} (or a plain {@code Source}, + * which resolves to it), the application opts in to receiving the raw, + * unparsed request body. That body is not processed by this converter + * and the application is responsible for any later processing of it, including + * writing it back out in a response. Echoing untrusted XML back to the client + * is an application-level decision; the application must parse or sanitize + * that XML safely first (for example by declaring a {@code DOMSource}). + * + *
This behavior is by design and is not considered a vulnerability in
+ * Spring Framework. Reports of XXE on the write path, or from raw
+ * {@code StreamSource} pass-through, will be closed as such.
+ *
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @author Juergen Hoeller
@@ -102,8 +122,11 @@ public class SourceHttpMessageConverter Default is {@code false} meaning that DTD is disabled.
+ * This setting does not apply to raw {@code StreamSource} content or to
+ * writing {@code Source} instances; see the class-level documentation.
*/
public void setSupportDtd(boolean supportDtd) {
this.supportDtd = supportDtd;
@@ -122,6 +145,8 @@ public class SourceHttpMessageConverter Default is {@code false}, meaning that external entities are not resolved.
+ * This setting does not apply to raw {@code StreamSource} content or to
+ * writing {@code Source} instances; see the class-level documentation.
* Note: setting this option to {@code true} also
* automatically sets {@link #setSupportDtd} to {@code true}.
*/