Added tests for SpringHttpInvokerUnsafeDeserialization.ql

This commit is contained in:
Artem Smotrakov
2021-02-21 22:19:53 +01:00
parent 95284ad71d
commit aac0c27dcd
8 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1 @@
| SpringHttpInvokerUnsafeDeserialization.java:9:32:9:37 | unsafe | Unasafe deserialization in a remote service exporter in 'unsafe' method |

View File

@@ -0,0 +1,45 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
@Configuration
public class SpringHttpInvokerUnsafeDeserialization {
@Bean(name = "/unsafe")
HttpInvokerServiceExporter unsafe() {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(new AccountServiceImpl());
exporter.setServiceInterface(AccountService.class);
return exporter;
}
HttpInvokerServiceExporter notABean() {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(new AccountServiceImpl());
exporter.setServiceInterface(AccountService.class);
return exporter;
}
}
class NotAConfiguration {
@Bean(name = "/notAnEndpoint")
HttpInvokerServiceExporter notAnEndpoint() {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(new AccountServiceImpl());
exporter.setServiceInterface(AccountService.class);
return exporter;
}
}
class AccountServiceImpl implements AccountService {
@Override
public String echo(String data) {
return data;
}
}
interface AccountService {
String echo(String data);
}

View File

@@ -0,0 +1 @@
experimental/Security/CWE/CWE-502/SpringHttpInvokerUnsafeDeserialization.ql

View File

@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/springframework-5.2.3

View File

@@ -0,0 +1,10 @@
package org.springframework.context.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
public @interface Bean {
String[] name() default {};
}

View File

@@ -0,0 +1,7 @@
package org.springframework.context.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
public @interface Configuration {}

View File

@@ -0,0 +1,8 @@
package org.springframework.remoting.httpinvoker;
public class HttpInvokerServiceExporter extends org.springframework.remoting.rmi.RemoteInvocationSerializingExporter {
public void setService(Object service) {}
public void setServiceInterface(Class clazz) {}
}

View File

@@ -0,0 +1,5 @@
package org.springframework.remoting.rmi;
public abstract class RemoteInvocationSerializingExporter {
}