Skip to content

Commit aac0c27

Browse files
Added tests for SpringHttpInvokerUnsafeDeserialization.ql
1 parent 95284ad commit aac0c27

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| SpringHttpInvokerUnsafeDeserialization.java:9:32:9:37 | unsafe | Unasafe deserialization in a remote service exporter in 'unsafe' method |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import org.springframework.context.annotation.Bean;
2+
import org.springframework.context.annotation.Configuration;
3+
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
4+
5+
@Configuration
6+
public class SpringHttpInvokerUnsafeDeserialization {
7+
8+
@Bean(name = "/unsafe")
9+
HttpInvokerServiceExporter unsafe() {
10+
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
11+
exporter.setService(new AccountServiceImpl());
12+
exporter.setServiceInterface(AccountService.class);
13+
return exporter;
14+
}
15+
16+
HttpInvokerServiceExporter notABean() {
17+
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
18+
exporter.setService(new AccountServiceImpl());
19+
exporter.setServiceInterface(AccountService.class);
20+
return exporter;
21+
}
22+
}
23+
24+
class NotAConfiguration {
25+
26+
@Bean(name = "/notAnEndpoint")
27+
HttpInvokerServiceExporter notAnEndpoint() {
28+
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
29+
exporter.setService(new AccountServiceImpl());
30+
exporter.setServiceInterface(AccountService.class);
31+
return exporter;
32+
}
33+
}
34+
35+
class AccountServiceImpl implements AccountService {
36+
37+
@Override
38+
public String echo(String data) {
39+
return data;
40+
}
41+
}
42+
43+
interface AccountService {
44+
String echo(String data);
45+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-502/SpringHttpInvokerUnsafeDeserialization.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/springframework-5.2.3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.springframework.context.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Target;
5+
6+
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
7+
public @interface Bean {
8+
9+
String[] name() default {};
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.context.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Target;
5+
6+
@Target(ElementType.TYPE)
7+
public @interface Configuration {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.springframework.remoting.httpinvoker;
2+
3+
public class HttpInvokerServiceExporter extends org.springframework.remoting.rmi.RemoteInvocationSerializingExporter {
4+
5+
public void setService(Object service) {}
6+
7+
public void setServiceInterface(Class clazz) {}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.springframework.remoting.rmi;
2+
3+
public abstract class RemoteInvocationSerializingExporter {
4+
5+
}

0 commit comments

Comments
 (0)