1+ import java .io .ObjectInputStream ;
12import java .rmi .Naming ;
23import java .rmi .Remote ;
34import java .rmi .RemoteException ;
@@ -10,15 +11,47 @@ public class RmiUnsafeDeserialization {
1011 public static void testRegistryBindWithObjectParameter () throws Exception {
1112 Registry registry = LocateRegistry .createRegistry (1099 );
1213 registry .bind ("test" , new RemoteObjectWithObject ());
14+ registry .rebind ("test" , new RemoteObjectWithObject ());
15+ }
16+
17+ // GOOD (bind a remote object that has methods that takes safe parameters)
18+ public static void testRegistryBindWithIntParameter () throws Exception {
19+ Registry registry = LocateRegistry .createRegistry (1099 );
20+ registry .bind ("test" , new SafeRemoteObject ());
21+ registry .rebind ("test" , new SafeRemoteObject ());
22+ }
23+
24+ // BAD (bind a remote object that has a vulnerable method that takes Object)
25+ public static void testNamingBindWithObjectParameter () throws Exception {
26+ Naming .bind ("test" , new RemoteObjectWithObject ());
27+ Naming .rebind ("test" , new RemoteObjectWithObject ());
28+ }
29+
30+ // GOOD (bind a remote object that has methods that takes safe parameters)
31+ public static void testNamingBindWithIntParameter () throws Exception {
32+ Naming .bind ("test" , new SafeRemoteObject ());
33+ Naming .rebind ("test" , new SafeRemoteObject ());
1334 }
1435}
1536
1637interface RemoteObjectWithObjectInterface extends Remote {
17-
1838 void take (Object obj ) throws RemoteException ;
1939}
2040
2141class RemoteObjectWithObject implements RemoteObjectWithObjectInterface {
22-
2342 public void take (Object obj ) throws RemoteException {}
2443}
44+
45+ interface SafeRemoteObjectInterface extends Remote {
46+ void take (int n ) throws RemoteException ;
47+ void take (double n ) throws RemoteException ;
48+ void take (String s ) throws RemoteException ;
49+ void take (ObjectInputStream ois ) throws RemoteException ;
50+ }
51+
52+ class SafeRemoteObject implements SafeRemoteObjectInterface {
53+ public void take (int n ) throws RemoteException {}
54+ public void take (double n ) throws RemoteException {}
55+ public void take (String s ) throws RemoteException {}
56+ public void take (ObjectInputStream ois ) throws RemoteException {}
57+ }
0 commit comments