Skip to content

Commit b7448d5

Browse files
committed
Introduce TaintInheritingContent instead of using parts of DataFlowPrivate
1 parent f88c8a6 commit b7448d5

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

java/ql/lib/semmle/code/java/dataflow/FlowSteps.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,19 @@ private class NumberTaintPreservingCallable extends TaintPreservingCallable {
103103

104104
override predicate returnsTaintFrom(int arg) { arg = argument }
105105
}
106+
107+
/**
108+
* A `Content` that should be implicitly regarded as tainted whenever an object with such `Content`
109+
* is itself tainted.
110+
*
111+
* For example, if we had a type `class Container { Contained field; }`, then by default a tainted
112+
* `Container` and a `Container` with a tainted `Contained` stored in its `field` are distinct.
113+
*
114+
* If `any(DataFlow::FieldContent fc | fc.getField().hasQualifiedName("Container", "field"))` was
115+
* included in this type however, then a tainted `Container` would imply that its `field` is also
116+
* tainted (but not vice versa).
117+
*
118+
* Note that `TaintTracking::Configuration` applies this behaviour by default to array, collection,
119+
* map-key and map-value content, so that e.g. a tainted `Map` is assumed to have tainted keys and values.
120+
*/
121+
abstract class TaintInheritingContent extends DataFlow::Content { }

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ private module Cached {
8383
not sink.getTypeBound() instanceof PrimitiveType and
8484
not sink.getTypeBound() instanceof BoxedType and
8585
not sink.getTypeBound() instanceof NumberType and
86-
containerContent(f)
86+
(
87+
containerContent(f)
88+
or
89+
f instanceof TaintInheritingContent
90+
)
8791
)
8892
or
8993
FlowSummaryImpl::Private::Steps::summaryLocalStep(src, sink, false)

java/ql/lib/semmle/code/java/frameworks/android/Intent.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import java
2+
private import semmle.code.java.dataflow.DataFlow
23
import semmle.code.java.dataflow.FlowSteps
34
import semmle.code.java.dataflow.ExternalFlow
45

@@ -54,6 +55,14 @@ class BundleGetterMethod extends Method, TaintPreservingCallable {
5455
override predicate returnsTaintFrom(int arg) { arg = -1 }
5556
}
5657

58+
/**
59+
* Specifies that if an `Intent` is tainted, then so are its synthetic fields.
60+
*/
61+
private class IntentFieldsInheritTaint extends DataFlow::SyntheticFieldContent,
62+
TaintInheritingContent {
63+
IntentFieldsInheritTaint() { this.getField().matches("android.content.Intent.%") }
64+
}
65+
5766
private class IntentBundleFlowSteps extends SummaryModelCsv {
5867
override predicate row(string row) {
5968
row =

java/ql/src/experimental/Security/CWE/CWE-200/SensitiveAndroidFileLeak.ql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import semmle.code.java.controlflow.Guards
1414
import AndroidFileIntentSink
1515
import AndroidFileIntentSource
1616
import DataFlow::PathGraph
17-
// For readStep, to implement `isAdditionalTaintStep`
18-
private import semmle.code.java.dataflow.internal.DataFlowPrivate
1917

2018
private class StartsWithSanitizer extends DataFlow::BarrierGuard {
2119
StartsWithSanitizer() { this.(MethodAccess).getMethod().hasName("startsWith") }
@@ -73,11 +71,6 @@ class AndroidFileLeakConfig extends TaintTracking::Configuration {
7371
prev.asExpr() = csma.getArgument(0) and
7472
succ.asParameter() = ssm.getParameter(0) // public int onStartCommand(Intent intent, int flags, int startId) {...} in FileUploader
7573
)
76-
or
77-
// When a whole Intent is tainted (e.g., due to this Configuration's source), treat its fields as tainted
78-
readStep(prev,
79-
any(DataFlow::SyntheticFieldContent c | c.getField().matches("android.content.Intent.%")),
80-
succ)
8174
}
8275

8376
override predicate isSanitizerGuard(DataFlow::BarrierGuard guard) {

0 commit comments

Comments
 (0)