Preserve taint on field-read-steps on entrypoint types

This commit is contained in:
Tony Torralba
2021-06-17 16:09:56 +02:00
parent 9363d64166
commit 5e80044f11
4 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
public class EntryPointTypesTest {
static class TestObject {
public String field1;
private String field2;
private AnotherTestObject field3;
public String getField2() {
return field2;
}
public AnotherTestObject getField3() {
return field3;
}
}
static class AnotherTestObject {
public String field4;
private String field5;
public String getField5() {
return field5;
}
}
private static void sink(String sink) {}
public static void test(TestObject source) {
sink(source.field1); // $hasTaintFlow
sink(source.getField2()); // $hasTaintFlow
sink(source.getField3().field4); // $hasTaintFlow
sink(source.getField3().getField5()); // $hasTaintFlow
}
}

View File

@@ -0,0 +1,34 @@
import java
import semmle.code.java.dataflow.FlowSources
import TestUtilities.InlineExpectationsTest
class TestRemoteFlowSource extends RemoteFlowSource {
TestRemoteFlowSource() { this.asParameter().hasName("source") }
override string getSourceType() { result = "test" }
}
class TaintFlowConf extends TaintTracking::Configuration {
TaintFlowConf() { this = "qltest:dataflow:entrypoint-types-taint" }
override predicate isSource(DataFlow::Node n) { n instanceof RemoteFlowSource }
override predicate isSink(DataFlow::Node n) {
exists(MethodAccess ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
}
}
class HasFlowTest extends InlineExpectationsTest {
HasFlowTest() { this = "HasFlowTest" }
override string getARelevantTag() { result = ["hasTaintFlow"] }
override predicate hasActualResult(Location location, string element, string tag, string value) {
tag = "hasTaintFlow" and
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf | conf.hasFlow(src, sink) |
sink.getLocation() = location and
element = sink.toString() and
value = ""
)
}
}