Skip to content

Commit 2ee9a45

Browse files
committed
Use proper class inheritance
1 parent 3cc3fe9 commit 2ee9a45

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -307,36 +307,26 @@ class ReverseDNSMethod extends Method {
307307

308308
/** Android `Intent` that may have come from a hostile application. */
309309
class AndroidIntentInput extends DataFlow::Node {
310+
Type receiverType;
311+
310312
AndroidIntentInput() {
311313
exists(MethodAccess ma, AndroidGetIntentMethod m |
312314
ma.getMethod().overrides*(m) and
313-
this.asExpr() = ma
315+
this.asExpr() = ma and
316+
receiverType = ma.getEnclosingCallable().getDeclaringType()
314317
)
315318
or
316319
exists(Method m, AndroidReceiveIntentMethod rI |
317320
m.overrides*(rI) and
318-
this.asParameter() = m.getParameter(1)
321+
this.asParameter() = m.getParameter(1) and
322+
receiverType = m.getDeclaringType()
319323
)
320324
}
321325
}
322326

323327
/** Exported Android `Intent` that may have come from a hostile application. */
324-
class ExportedAndroidIntentInput extends RemoteFlowSource {
325-
ExportedAndroidIntentInput() {
326-
exists(ExportableAndroidComponent exportedType | exportedType.isExported() |
327-
exists(MethodAccess ma, AndroidGetIntentMethod m |
328-
ma.getMethod().overrides*(m) and
329-
this.asExpr() = ma and
330-
exportedType = ma.getEnclosingCallable().getDeclaringType()
331-
)
332-
or
333-
exists(Method m, AndroidReceiveIntentMethod rI |
334-
m.overrides*(rI) and
335-
this.asParameter() = m.getParameter(1) and
336-
exportedType = m.getDeclaringType()
337-
)
338-
)
339-
}
328+
class ExportedAndroidIntentInput extends RemoteFlowSource, AndroidIntentInput {
329+
ExportedAndroidIntentInput() { receiverType.(ExportableAndroidComponent).isExported() }
340330

341-
override string getSourceType() { result = "Android intent source" }
331+
override string getSourceType() { result = "Exported Android intent source" }
342332
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AndroidComponent extends Class {
3131
}
3232

3333
/**
34-
* An Android component that is explicitly or implicitly exported.
34+
* An Android component that can be explicitly or implicitly exported.
3535
*/
3636
class ExportableAndroidComponent extends AndroidComponent {
3737
/** Holds if this Android component is configured as `exported` or has intent filters configured without `exported` explicitly disabled in an `AndroidManifest.xml` file. */

java/ql/test/experimental/query-tests/security/CWE-749/UnsafeActivity4.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import android.webkit.WebViewClient;
1010

1111
public class UnsafeActivity4 extends Activity {
12-
//Test onCreate with both JavaScript and cross-origin resource access enabled while taking remote user inputs from bundle extras
12+
/**
13+
* Test onCreate with both JavaScript and cross-origin resource access enabled while taking remote user inputs from bundle extras
14+
* Note this case of invoking utility method that takes an Activity a then calls `a.getIntent().getStringExtra(...)` is not yet detected thus is beyond what the query is capable of.
15+
*/
1316
public void onCreate(Bundle savedInstanceState) {
1417
super.onCreate(savedInstanceState);
1518
setContentView(-1);

0 commit comments

Comments
 (0)