You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java/ql/src/experimental/Security/CWE/CWE-502/UnsafeDeserializationRmi.qhelp
+19-7Lines changed: 19 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -15,32 +15,44 @@ In the worst case, it results in remote code execution.
15
15
<p>
16
16
Use only strings and primitive types in parameters of remote objects.
17
17
</p>
18
+
</p>
19
+
Set a filter for incoming serialized data by wrapping remote objects using either <code>UnicastRemoteObject.exportObject(Remote, int, ObjectInputFilter)</code>
20
+
or <code>UnicastRemoteObject.exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory, ObjectInputFilter)</code> methods.
21
+
Those methods accept an <code>ObjectInputFilter</code> that decides which classes are allowed for deserialization.
22
+
The filter should allow deserializing only safe classes.
23
+
</p>
18
24
<p>
19
-
Java RMI does not offer API for specifying classes which are only allowed for deserialization.
20
-
However, it is possible to set a process-wide deserialization filter that was introduced in JEP 290.
21
-
The filter can be set via system or security property <code>jdk.serialFilter</code>.
25
+
It is also possible to set a process-wide deserialization filter.
26
+
The filter can be set by with <code>ObjectInputFilter.Config.setSerialFilter(ObjectInputFilter)</code> method,
27
+
or by setting system or security property <code>jdk.serialFilter</code>.
22
28
Make sure that you use the latest Java versions that include JEP 290.
23
29
</p>
24
30
<p>
25
-
Consider using other implementations of remote procedure calls. For example, HTTP API with JSON.
31
+
If switching to the latest Java versions is not possible,
32
+
consider using other implementations of remote procedure calls. For example, HTTP API with JSON.
26
33
Make sure that the underlying deserialization mechanism is properly configured
27
34
so that deserialization attacks are not possible.
28
35
</p>
29
36
</recommendation>
30
37
31
38
<example>
32
39
<p>
33
-
The following code registers a vulnerable remote object
34
-
which has a method that accepts a complex object:
40
+
The following code registers a remote object
41
+
with a vulnerable method that accepts a complex object:
35
42
</p>
36
43
<samplesrc="RmiUnsafeRemoteObject.java" />
37
44
38
45
<p>
39
46
The next example registers a safe remote object
40
-
which has methods that use only primitive types and strings:
47
+
whose methods use only primitive types and strings:
41
48
</p>
42
49
<samplesrc="RmiSafeRemoteObject.java" />
43
50
51
+
<p>
52
+
The next example shows how to set a deserilization filter for a remote object:
0 commit comments