Skip to content

Commit e28f919

Browse files
Look for remote callable method only in RmiUnsafeDeserialization.ql
1 parent 0182dfe commit e28f919

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

java/ql/src/experimental/Security/CWE/CWE-502/RmiSafeRemoteObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
public class Server {
22
public static void main(String... args) throws Exception {
33
Registry registry = LocateRegistry.createRegistry(1099);
4-
registry.bind("unsafe", new RemoteObjectImpl());
4+
registry.bind("safe", new RemoteObjectImpl());
55
}
66
}
77

java/ql/src/experimental/Security/CWE/CWE-502/RmiUnsafeDeserialization.ql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java
1616
import semmle.code.java.frameworks.Rmi
1717

18-
private class ObjectInputStream extends RefType {
18+
private class ObjectInputStream extends Class {
1919
ObjectInputStream() { hasQualifiedName("java.io", "ObjectInputStream") }
2020
}
2121

@@ -35,9 +35,8 @@ private class BindMethod extends Method {
3535
/**
3636
* Looks for a vulnerable method in a `Remote` object.
3737
*/
38-
private Method getVulnerableMethod(Type type) {
39-
type.(RefType).getASupertype*() instanceof TypeRemote and
40-
exists(Method m, Type parameterType |
38+
private Method getVulnerableMethod(RefType type) {
39+
exists(RemoteCallableMethod m, Type parameterType |
4140
m.getDeclaringType() = type and parameterType = m.getAParamType()
4241
|
4342
not parameterType instanceof PrimitiveType and
@@ -61,5 +60,7 @@ private class UnsafeRmiBinding extends MethodAccess {
6160
Method getVulnerableMethod() { result = vulnerableMethod }
6261
}
6362

64-
from UnsafeRmiBinding call
65-
select call, "Unsafe deserialization with RMI in '" + call.getVulnerableMethod() + "' method"
63+
from UnsafeRmiBinding call, Method vulnerableMethod
64+
where vulnerableMethod = call.getVulnerableMethod()
65+
select call, "Unsafe deserialization with RMI in '$@' method", vulnerableMethod,
66+
vulnerableMethod.getStringSignature()
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| RmiUnsafeDeserialization.java:13:9:13:59 | bind(...) | Unsafe deserialization with RMI in 'take' method |
2-
| RmiUnsafeDeserialization.java:14:9:14:61 | rebind(...) | Unsafe deserialization with RMI in 'take' method |
3-
| RmiUnsafeDeserialization.java:26:9:26:57 | bind(...) | Unsafe deserialization with RMI in 'take' method |
4-
| RmiUnsafeDeserialization.java:27:9:27:59 | rebind(...) | Unsafe deserialization with RMI in 'take' method |
1+
| RmiUnsafeDeserialization.java:13:9:13:59 | bind(...) | Unsafe deserialization with RMI in '$@' method | RmiUnsafeDeserialization.java:42:17:42:20 | take | take(Object) |
2+
| RmiUnsafeDeserialization.java:14:9:14:61 | rebind(...) | Unsafe deserialization with RMI in '$@' method | RmiUnsafeDeserialization.java:42:17:42:20 | take | take(Object) |
3+
| RmiUnsafeDeserialization.java:26:9:26:57 | bind(...) | Unsafe deserialization with RMI in '$@' method | RmiUnsafeDeserialization.java:42:17:42:20 | take | take(Object) |
4+
| RmiUnsafeDeserialization.java:27:9:27:59 | rebind(...) | Unsafe deserialization with RMI in '$@' method | RmiUnsafeDeserialization.java:42:17:42:20 | take | take(Object) |

java/ql/test/experimental/query-tests/security/CWE-502/RmiUnsafeDeserialization.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ public void take(int n) throws RemoteException {}
5454
public void take(double n) throws RemoteException {}
5555
public void take(String s) throws RemoteException {}
5656
public void take(ObjectInputStream ois) throws RemoteException {}
57+
public void safeMethod(Object object) {} // this method is not declared in SafeRemoteObjectInterface
5758
}

0 commit comments

Comments
 (0)