Skip to content

Commit 2236262

Browse files
committed
Up-to-date guidelines for serialization-based endpoints
Issue: SPR-15317
1 parent b90d3d0 commit 2236262

File tree

7 files changed

+59
-43
lines changed

7 files changed

+59
-43
lines changed

spring-web/src/main/java/org/springframework/remoting/httpinvoker/AbstractHttpInvokerRequestExecutor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,14 +43,15 @@
4343
* @since 1.1
4444
* @see #doExecuteRequest
4545
*/
46-
public abstract class AbstractHttpInvokerRequestExecutor
47-
implements HttpInvokerRequestExecutor, BeanClassLoaderAware {
46+
public abstract class AbstractHttpInvokerRequestExecutor implements HttpInvokerRequestExecutor, BeanClassLoaderAware {
4847

4948
/**
5049
* Default content type: "application/x-java-serialized-object"
5150
*/
5251
public static final String CONTENT_TYPE_SERIALIZED_OBJECT = "application/x-java-serialized-object";
5352

53+
private static final int SERIALIZED_INVOCATION_BYTE_ARRAY_INITIAL_SIZE = 1024;
54+
5455

5556
protected static final String HTTP_METHOD_POST = "POST";
5657

@@ -67,9 +68,6 @@ public abstract class AbstractHttpInvokerRequestExecutor
6768
protected static final String ENCODING_GZIP = "gzip";
6869

6970

70-
private static final int SERIALIZED_INVOCATION_BYTE_ARRAY_INITIAL_SIZE = 1024;
71-
72-
7371
protected final Log logger = LogFactory.getLog(getClass());
7472

7573
private String contentType = CONTENT_TYPE_SERIALIZED_OBJECT;

spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,14 +46,19 @@
4646
* a security context). Furthermore, it allows to customize request
4747
* execution via the {@link HttpInvokerRequestExecutor} strategy.
4848
*
49-
* <p>Can use the JDK's {@link java.rmi.server.RMIClassLoader} to load
50-
* classes from a given {@link #setCodebaseUrl codebase}, performing
51-
* on-demand dynamic code download from a remote location. The codebase
52-
* can consist of multiple URLs, separated by spaces. Note that
53-
* RMIClassLoader requires a SecurityManager to be set, analogous to
54-
* when using dynamic class download with standard RMI!
49+
* <p>Can use the JDK's {@link java.rmi.server.RMIClassLoader} to load classes
50+
* from a given {@link #setCodebaseUrl codebase}, performing on-demand dynamic
51+
* code download from a remote location. The codebase can consist of multiple
52+
* URLs, separated by spaces. Note that RMIClassLoader requires a SecurityManager
53+
* to be set, analogous to when using dynamic class download with standard RMI!
5554
* (See the RMI documentation for details.)
5655
*
56+
* <p><b>WARNING: Be aware of vulnerabilities due to unsafe Java deserialization:
57+
* Manipulated input streams could lead to unwanted code execution on the server
58+
* during the deserialization step. As a consequence, do not expose HTTP invoker
59+
* endpoints to untrusted clients but rather just between your own services.</b>
60+
* In general, we strongly recommend any other message format (e.g. JSON) instead.
61+
*
5762
* @author Juergen Hoeller
5863
* @since 1.1
5964
* @see #setServiceUrl

spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerProxyFactoryBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Manipulated input streams could lead to unwanted code execution on the server
4141
* during the deserialization step. As a consequence, do not expose HTTP invoker
4242
* endpoints to untrusted clients but rather just between your own services.</b>
43+
* In general, we strongly recommend any other message format (e.g. JSON) instead.
4344
*
4445
* @author Juergen Hoeller
4546
* @since 1.1
@@ -51,8 +52,7 @@
5152
* @see org.springframework.remoting.rmi.RmiProxyFactoryBean
5253
* @see org.springframework.remoting.caucho.HessianProxyFactoryBean
5354
*/
54-
public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor
55-
implements FactoryBean<Object> {
55+
public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor implements FactoryBean<Object> {
5656

5757
private Object serviceProxy;
5858

spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpInvokerServiceExporter.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@
5252
* Manipulated input streams could lead to unwanted code execution on the server
5353
* during the deserialization step. As a consequence, do not expose HTTP invoker
5454
* endpoints to untrusted clients but rather just between your own services.</b>
55+
* In general, we strongly recommend any other message format (e.g. JSON) instead.
5556
*
5657
* @author Juergen Hoeller
5758
* @since 1.1
@@ -60,8 +61,7 @@
6061
* @see org.springframework.remoting.rmi.RmiServiceExporter
6162
* @see org.springframework.remoting.caucho.HessianServiceExporter
6263
*/
63-
public class HttpInvokerServiceExporter extends RemoteInvocationSerializingExporter
64-
implements HttpRequestHandler {
64+
public class HttpInvokerServiceExporter extends RemoteInvocationSerializingExporter implements HttpRequestHandler {
6565

6666
/**
6767
* Reads a remote invocation from the request, executes it,
@@ -86,10 +86,8 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
8686

8787
/**
8888
* Read a RemoteInvocation from the given HTTP request.
89-
* <p>Delegates to
90-
* {@link #readRemoteInvocation(javax.servlet.http.HttpServletRequest, java.io.InputStream)}
91-
* with the
92-
* {@link javax.servlet.ServletRequest#getInputStream() servlet request's input stream}.
89+
* <p>Delegates to {@link #readRemoteInvocation(HttpServletRequest, InputStream)} with
90+
* the {@link HttpServletRequest#getInputStream() servlet request's input stream}.
9391
* @param request current HTTP request
9492
* @return the RemoteInvocation object
9593
* @throws IOException in case of I/O failure
@@ -205,12 +203,10 @@ protected OutputStream decorateOutputStream(
205203
/**
206204
* Decorate an {@code OutputStream} to guard against {@code flush()} calls,
207205
* which are turned into no-ops.
208-
*
209206
* <p>Because {@link ObjectOutputStream#close()} will in fact flush/drain
210207
* the underlying stream twice, this {@link FilterOutputStream} will
211208
* guard against individual flush calls. Multiple flush calls can lead
212209
* to performance issues, since writes aren't gathered as they should be.
213-
*
214210
* @see <a href="https://jira.spring.io/browse/SPR-14040">SPR-14040</a>
215211
*/
216212
private static class FlushGuardedOutputStream extends FilterOutputStream {

spring-web/src/main/java/org/springframework/remoting/httpinvoker/SimpleHttpInvokerServiceExporter.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,22 +45,27 @@
4545
* being tied to Java. Nevertheless, it is as easy to set up as Hessian,
4646
* which is its main advantage compared to RMI.
4747
*
48+
* <p><b>WARNING: Be aware of vulnerabilities due to unsafe Java deserialization:
49+
* Manipulated input streams could lead to unwanted code execution on the server
50+
* during the deserialization step. As a consequence, do not expose HTTP invoker
51+
* endpoints to untrusted clients but rather just between your own services.</b>
52+
* In general, we strongly recommend any other message format (e.g. JSON) instead.
53+
*
4854
* @author Juergen Hoeller
4955
* @since 2.5.1
5056
* @see org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor
5157
* @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
5258
* @see org.springframework.remoting.caucho.SimpleHessianServiceExporter
5359
*/
5460
@UsesSunHttpServer
55-
public class SimpleHttpInvokerServiceExporter extends RemoteInvocationSerializingExporter
56-
implements HttpHandler {
61+
public class SimpleHttpInvokerServiceExporter extends RemoteInvocationSerializingExporter implements HttpHandler {
5762

5863
/**
5964
* Reads a remote invocation from the request, executes it,
6065
* and writes the remote invocation result to the response.
61-
* @see #readRemoteInvocation(com.sun.net.httpserver.HttpExchange)
62-
* @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object)
63-
* @see #writeRemoteInvocationResult(com.sun.net.httpserver.HttpExchange, org.springframework.remoting.support.RemoteInvocationResult)
66+
* @see #readRemoteInvocation(HttpExchange)
67+
* @see #invokeAndCreateResult(RemoteInvocation, Object)
68+
* @see #writeRemoteInvocationResult(HttpExchange, RemoteInvocationResult)
6469
*/
6570
@Override
6671
public void handle(HttpExchange exchange) throws IOException {
@@ -78,10 +83,8 @@ public void handle(HttpExchange exchange) throws IOException {
7883

7984
/**
8085
* Read a RemoteInvocation from the given HTTP request.
81-
* <p>Delegates to
82-
* {@link #readRemoteInvocation(com.sun.net.httpserver.HttpExchange, java.io.InputStream)}
83-
* with the
84-
* {@link com.sun.net.httpserver.HttpExchange#getRequestBody()} request's input stream}.
86+
* <p>Delegates to {@link #readRemoteInvocation(HttpExchange, InputStream)}
87+
* with the {@link HttpExchange#getRequestBody()} request's input stream}.
8588
* @param exchange current HTTP request/response
8689
* @return the RemoteInvocation object
8790
* @throws java.io.IOException in case of I/O failure

src/asciidoc/data-access.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6651,13 +6651,13 @@ which consists of string aliases mapped to classes:
66516651

66526652
[WARNING]
66536653
====
6654-
6655-
By default, XStream allows for arbitrary classes to be unmarshalled, which can result in
6656-
security vulnerabilities. As such, it is __not recommended to use the
6654+
By default, XStream allows for arbitrary classes to be unmarshalled, which can lead to
6655+
unsafe Java serialization effects. As such, it is __not recommended to use the
66576656
`XStreamMarshaller` to unmarshal XML from external sources__ (i.e. the Web), as this can
6658-
result in __security vulnerabilities__. If you do use the `XStreamMarshaller` to
6659-
unmarshal XML from an external source, set the `supportedClasses` property on the
6660-
`XStreamMarshaller`, like so:
6657+
result in __security vulnerabilities__.
6658+
6659+
If you choose to use the `XStreamMarshaller` to unmarshal XML from an external source,
6660+
set the `supportedClasses` property on the `XStreamMarshaller`, like as follows:
66616661
66626662
[source,xml,indent=0]
66636663
[subs="verbatim,quotes"]

src/asciidoc/integration.adoc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ advanced and easier-to-use functionality. Refer to
377377
http://hc.apache.org/httpcomponents-client-ga/[hc.apache.org/httpcomponents-client-ga/]
378378
for more information.
379379

380+
[WARNING]
381+
====
382+
Be aware of vulnerabilities due to unsafe Java deserialization:
383+
Manipulated input streams could lead to unwanted code execution on the server
384+
during the deserialization step. As a consequence, do not expose HTTP invoker
385+
endpoints to untrusted clients but rather just between your own services.
386+
In general, we strongly recommend any other message format (e.g. JSON) instead.
387+
388+
If you are concerned about security vulnerabilities due to Java serialization,
389+
consider the general-purpose serialization filter mechanism at the core JVM level,
390+
originally developed for JDK 9 but backported to JDK 8, 7 and 6 in the meantime:
391+
https://blogs.oracle.com/java-platform-group/entry/incoming_filter_serialization_data_a
392+
http://openjdk.java.net/jeps/290
393+
====
394+
380395

381396

382397
[[remoting-httpinvoker-server]]
@@ -2499,15 +2514,15 @@ be obtained from JNDI instead (using `<jee:jndi-lookup>`). The Spring-based mess
24992514
listeners can then interact with the server-hosted `ResourceAdapter`, also using the
25002515
server's built-in `WorkManager`.
25012516

2502-
Please consult the JavaDoc for `JmsMessageEndpointManager`, `JmsActivationSpecConfig`,
2517+
Please consult the javadoc for `JmsMessageEndpointManager`, `JmsActivationSpecConfig`,
25032518
and `ResourceAdapterFactoryBean` for more details.
25042519

25052520
Spring also provides a generic JCA message endpoint manager which is not tied to JMS:
25062521
`org.springframework.jca.endpoint.GenericMessageEndpointManager`. This component allows
25072522
for using any message listener type (e.g. a CCI MessageListener) and any
25082523
provider-specific ActivationSpec object. Check out your JCA provider's documentation to
25092524
find out about the actual capabilities of your connector, and consult
2510-
`GenericMessageEndpointManager`'s JavaDoc for the Spring-specific configuration details.
2525+
`GenericMessageEndpointManager`'s javadoc for the Spring-specific configuration details.
25112526

25122527
[NOTE]
25132528
====
@@ -5966,7 +5981,6 @@ along with an inline image.
59665981

59675982
[WARNING]
59685983
====
5969-
59705984
Inline resources are added to the mime message using the specified `Content-ID` (
59715985
`identifier1234` in the above example). The order in which you are adding the text and
59725986
the resource are __very__ important. Be sure to __first add the text__ and after that

0 commit comments

Comments
 (0)