Skip to content

Commit 18e33b1

Browse files
authored
Merge pull request #20589 from aschackmull/java/array-entrypoint-read-taint
Java: Allow taint-read-steps for array sources.
2 parents ea4d475 + 7dadbc4 commit 18e33b1

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fields of certain objects are considered tainted if the object is tainted. This holds, for example, for objects that occur directly as sources in the active threat model (for instance, a remote flow source). This has now been amended to also include array types, such that if an array like `MyPojo[]` is a source, then fields of a tainted `MyPojo` are now also considered tainted.

java/ql/lib/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ private SrcRefType entrypointType() {
655655
)
656656
or
657657
result = entrypointType().getAField().getType().(RefType).getSourceDeclaration()
658+
or
659+
result = entrypointType().(Array).getElementType().(RefType).getSourceDeclaration()
658660
}
659661

660662
private predicate entrypointFieldStep(DataFlow::Node src, DataFlow::Node sink) {

java/ql/test/library-tests/dataflow/entrypoint-types/EntryPointTypesTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class UnrelatedObject {
4141
public String safeField;
4242
}
4343

44+
static class ArrayElemObject {
45+
public String field;
46+
}
47+
4448
private static void sink(String sink) {}
4549

4650
public static void test(TestObject source) {
@@ -70,4 +74,8 @@ public static void testSubtype(ParameterizedTestObject<?, ?> source) {
7074
UnrelatedObject unrelated = (UnrelatedObject) subtypeSource.getField8();
7175
sink(unrelated.safeField); // Safe
7276
}
77+
78+
public static void testArray(ArrayElemObject[] source) {
79+
sink(source[0].field); // $hasTaintFlow
80+
}
7381
}

0 commit comments

Comments
 (0)