Skip to content

Commit 9ae5689

Browse files
committed
Use AndroidIntentInput source
1 parent f5f7259 commit 9ae5689

File tree

2 files changed

+27
-52
lines changed

2 files changed

+27
-52
lines changed

java/ql/src/semmle/code/java/dataflow/FlowSources.qll

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -305,48 +305,22 @@ class ReverseDNSMethod extends Method {
305305
}
306306
}
307307

308-
/** Android `Intent` that may have come from a hostile application. */
309-
class AndroidIntentInput extends DataFlow::Node {
308+
/** Exported Android `Intent` that may have come from a hostile application. */
309+
class AndroidIntentInput extends RemoteFlowSource {
310310
AndroidIntentInput() {
311-
exists(MethodAccess ma, AndroidGetIntentMethod m |
312-
ma.getMethod().overrides*(m) and
313-
this.asExpr() = ma
314-
)
315-
or
316-
exists(Method m, AndroidReceiveIntentMethod rI |
317-
m.overrides*(rI) and
318-
this.asParameter() = m.getParameter(1)
319-
)
320-
}
321-
}
322-
323-
/** Method access to external inputs of `android.content.Intent` or `android.os.BaseBundle` object. */
324-
class IntentGetExtraMethodAccess extends MethodAccess {
325-
IntentGetExtraMethodAccess() {
326-
exists(AndroidComponent ac |
327-
this.getEnclosingCallable().getDeclaringType() = ac and
328-
ac.isExported() and
329-
this.getMethod().getName().regexpMatch("get\\w+Extra") and
330-
this.getMethod().getDeclaringType() instanceof TypeIntent
331-
)
332-
or
333-
this.getMethod().getName().regexpMatch("get\\w+") and
334-
this
335-
.getMethod()
336-
.getDeclaringType()
337-
.getASupertype*()
338-
.hasQualifiedName("android.os", "BaseBundle")
339-
}
340-
}
341-
342-
/** Android intent extra source. */
343-
private class AndroidIntentExtraSource extends RemoteFlowSource {
344-
AndroidIntentExtraSource() {
345-
exists(AndroidIntentInput inode |
346-
this.asExpr() = inode.asExpr() or
347-
this.asExpr() = inode.asParameter().getAnAccess()
311+
this.getEnclosingCallable().getDeclaringType().(AndroidComponent).isExported() and
312+
(
313+
exists(MethodAccess ma, AndroidGetIntentMethod m |
314+
ma.getMethod().overrides*(m) and
315+
this.asExpr() = ma
316+
)
317+
or
318+
exists(Method m, AndroidReceiveIntentMethod rI |
319+
m.overrides*(rI) and
320+
this.asParameter() = m.getParameter(1)
321+
)
348322
)
349323
}
350324

351-
override string getSourceType() { result = "Android intent extra" }
325+
override string getSourceType() { result = "Android intent source" }
352326
}

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,30 +141,31 @@ private class StringBuilderTaintPreservingCallable extends TaintPreservingCallab
141141
}
142142
}
143143

144-
/**
145-
* Holds if `n1` to `n2` is a dataflow step between the extra getter method and its caller Android `Intent` or `Bundle`.
146-
*/
147-
private predicate intentExtraStep(DataFlow::ExprNode n1, DataFlow::ExprNode n2) {
148-
exists(IntentGetExtraMethodAccess ma |
149-
n1.asExpr() = ma.getQualifier() and
150-
n2.asExpr() = ma
151-
)
144+
/** Method access to external inputs of `android.os.BaseBundle` object. */
145+
class GetBundleExtraMethodAccess extends MethodAccess {
146+
GetBundleExtraMethodAccess() {
147+
this.getMethod().getName().regexpMatch("get\\w+") and
148+
this
149+
.getMethod()
150+
.getDeclaringType()
151+
.getASupertype*()
152+
.hasQualifiedName("android.os", "BaseBundle")
153+
}
152154
}
153155

154156
/**
155-
* Holds if `n1` to `n2` is a dataflow step from Android `Intent` to its `getExtras` method.
157+
* Holds if `n1` to `n2` is a dataflow step between the extra getter method and its caller `Bundle`.
156158
*/
157159
private predicate bundleExtraStep(DataFlow::ExprNode n1, DataFlow::ExprNode n2) {
158-
exists(MethodAccess ma | ma.getMethod().hasName("getExtras") |
160+
exists(GetBundleExtraMethodAccess ma |
159161
n1.asExpr() = ma.getQualifier() and
160162
n2.asExpr() = ma
161163
)
162164
}
163165

164-
/** A set of additional taint steps to consider when taint tracking Android intent extra related data flows. */
166+
/** Additional taint step to consider when taint tracking Android intent extra related data flows. */
165167
class AndroidExtraSourceAdditionalTaintStep extends AdditionalTaintStep {
166168
override predicate step(DataFlow::Node node1, DataFlow::Node node2) {
167-
intentExtraStep(node1, node2) or
168169
bundleExtraStep(node1, node2)
169170
}
170171
}

0 commit comments

Comments
 (0)