Skip to content

Commit 95284ad

Browse files
Added SpringHttpInvokerUnsafeDeserialization.qhelp and example
1 parent 476309a commit 95284ad

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
4+
<overview>
5+
<p>
6+
Spring Framework provides an abstract base class <code>RemoteInvocationSerializingExporter</code>
7+
for defining remote service exporters.
8+
A Spring exporter, which is based on this class, deserializes incoming data using <code>ObjectInputStream</code>.
9+
Deserializing untrusted data is easily exploitable and in many cases allows an attacker
10+
to execute arbitrary code.
11+
</p>
12+
<p>
13+
Spring Framework also provides two classes that extend <code>RemoteInvocationSerializingExporter</code>:
14+
<li>
15+
<code>HttpInvokerServiceExporter</code>
16+
</li>
17+
<li>
18+
<code>SimpleHttpInvokerServiceExporter</code>
19+
</li>
20+
</p>
21+
<p>
22+
These classes export specified beans as HTTP endpoints that deserialize data from an HTTP request
23+
using unsafe <code>ObjectInputStream</code>. If a remote attacker can reach such endpoints,
24+
it results in remote code execution.
25+
</p>
26+
</overview>
27+
28+
<recommendation>
29+
<p>
30+
Avoid using <code>HttpInvokerServiceExporter</code>, <code>SimpleHttpInvokerServiceExporter</code>
31+
and other exporters that are based on <code>RemoteInvocationSerializingExporter</code>.
32+
Instead, use other message formats for API endpoints (for example, JSON),
33+
but make sure that the underlying deserialization mechanism is properly configured
34+
so that deserialization attacks are not possible. If the vulnerable exporters can not be replaced,
35+
consider using global deserialization filters introduced by JEP 290.
36+
In general, avoid deserialization of untrusted data.
37+
</p>
38+
</recommendation>
39+
40+
<example>
41+
<p>
42+
The following example defines a vulnerable HTTP endpoint:
43+
</p>
44+
<sample src="UnsafeHttpInvokerEndpoint.java" />
45+
</example>
46+
47+
<references>
48+
<li>
49+
OWASP:
50+
<a href="https://www.owasp.org/index.php/Deserialization_of_untrusted_data">Deserialization of untrusted data</a>.
51+
</li>
52+
<li>
53+
National Vulnerability Database:
54+
<a href="https://nvd.nist.gov/vuln/detail/CVE-2016-1000027">CVE-2016-1000027</a>
55+
</li>
56+
<li>
57+
Tenable Research Advisory:
58+
<a href="https://www.tenable.com/security/research/tra-2016-20">[R2] Pivotal Spring Framework HttpInvokerServiceExporter readRemoteInvocation Method Untrusted Java Deserialization</a>
59+
</li>
60+
<li>
61+
Spring Framework bug tracker:
62+
<a href="https://github.com/spring-projects/spring-framework/issues/24434">Sonatype vulnerability CVE-2016-1000027 in Spring-web project</a>
63+
</li>
64+
<li>
65+
OpenJDK:
66+
<a href="https://openjdk.java.net/jeps/290">JEP 290: Filter Incoming Serialization Data</a>
67+
</li>
68+
</references>
69+
</qhelp>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@Configuration
2+
public class Server {
3+
4+
@Bean(name = "/account")
5+
HttpInvokerServiceExporter accountService() {
6+
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
7+
exporter.setService(new AccountServiceImpl());
8+
exporter.setServiceInterface(AccountService.class);
9+
return exporter;
10+
}
11+
12+
}
13+
14+
class AccountServiceImpl implements AccountService {
15+
16+
@Override
17+
public String echo(String data) {
18+
return data;
19+
}
20+
}
21+
22+
interface AccountService {
23+
String echo(String data);
24+
}

0 commit comments

Comments
 (0)