mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Preserve taint on field-read-steps on entrypoint types
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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 = ""
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user