Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5ca459

Browse files
luchua-bcsmowton
authored andcommitted
Add remote source of Android intent extra
1 parent 08bf464 commit f5ca459

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import semmle.code.java.frameworks.spring.SpringWebClient
2323
import semmle.code.java.frameworks.Guice
2424
import semmle.code.java.frameworks.struts.StrutsActions
2525
import semmle.code.java.frameworks.Thrift
26+
import semmle.code.java.frameworks.android.Android
2627

2728
/** A data flow source of remote user input. */
2829
abstract class RemoteFlowSource extends DataFlow::Node {
@@ -318,3 +319,36 @@ class AndroidIntentInput extends DataFlow::Node {
318319
)
319320
}
320321
}
322+
323+
/**
324+
* Method access to external inputs of `android.content.Intent` object
325+
*/
326+
class IntentGetExtraMethodAccess extends MethodAccess {
327+
IntentGetExtraMethodAccess() {
328+
exists(AndroidComponent ac |
329+
this.getEnclosingCallable().getDeclaringType() = ac and ac.isExported()
330+
) and
331+
(
332+
this.getMethod().getName().regexpMatch("get\\w+Extra") and
333+
this.getMethod().getDeclaringType() instanceof TypeIntent
334+
or
335+
this.getMethod().getName().regexpMatch("get\\w+") and
336+
this.getQualifier().(MethodAccess).getMethod().hasName("getExtras") and
337+
this.getQualifier().(MethodAccess).getMethod().getDeclaringType() instanceof TypeIntent
338+
)
339+
}
340+
}
341+
342+
/**
343+
* Android intent extra source
344+
*/
345+
private class AndroidIntentExtraSource extends RemoteFlowSource {
346+
AndroidIntentExtraSource() {
347+
exists(MethodAccess ma |
348+
ma instanceof IntentGetExtraMethodAccess and
349+
this.asExpr().(VarAccess).getVariable().getAnAssignedValue() = ma
350+
)
351+
}
352+
353+
override string getSourceType() { result = "Android intent extra" }
354+
}

java/ql/src/semmle/code/java/frameworks/android/Android.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,39 @@ class AndroidComponent extends Class {
3333
/** An Android activity. */
3434
class AndroidActivity extends AndroidComponent {
3535
AndroidActivity() { this.getASupertype*().hasQualifiedName("android.app", "Activity") }
36+
37+
/** Holds if this Android component is configured as `exported` or has intent filters configured without `exported` explicitly disabled in an `AndroidManifest.xml` file. */
38+
override predicate isExported() {
39+
getAndroidComponentXmlElement().isExported()
40+
or
41+
not getAndroidComponentXmlElement().isNotExported() and hasIntentFilter()
42+
}
3643
}
3744

3845
/** An Android service. */
3946
class AndroidService extends AndroidComponent {
4047
AndroidService() { this.getASupertype*().hasQualifiedName("android.app", "Service") }
48+
49+
/** Holds if this Android component is configured as `exported` or has intent filters configured without `exported` explicitly disabled in an `AndroidManifest.xml` file. */
50+
override predicate isExported() {
51+
getAndroidComponentXmlElement().isExported()
52+
or
53+
not getAndroidComponentXmlElement().isNotExported() and hasIntentFilter()
54+
}
4155
}
4256

4357
/** An Android broadcast receiver. */
4458
class AndroidBroadcastReceiver extends AndroidComponent {
4559
AndroidBroadcastReceiver() {
4660
this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver")
4761
}
62+
63+
/** Holds if this Android component is configured as `exported` or has intent filters configured without `exported` explicitly disabled in an `AndroidManifest.xml` file. */
64+
override predicate isExported() {
65+
getAndroidComponentXmlElement().isExported()
66+
or
67+
not getAndroidComponentXmlElement().isNotExported() and hasIntentFilter()
68+
}
4869
}
4970

5071
/** An Android content provider. */

java/ql/src/semmle/code/xml/AndroidManifest.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ class AndroidComponentXmlElement extends XMLElement {
137137
* Holds if the `android:exported` attribute of this component element is `true`.
138138
*/
139139
predicate isExported() { getExportedAttributeValue() = "true" }
140+
141+
/**
142+
* Holds if the `android:exported` attribute of this component element is explicitly set to `false`.
143+
*/
144+
predicate isNotExported() { getExportedAttributeValue() = "false" }
140145
}
141146

142147
/**

0 commit comments

Comments
 (0)