Skip to content

Commit f88c8a6

Browse files
committed
Copyedit
1 parent b33daa3 commit f88c8a6

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

java/ql/src/experimental/Security/CWE/CWE-200/AndroidFileIntentSink.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AsyncTask extends RefType {
1919
AsyncTask() { this.hasQualifiedName("android.os", "AsyncTask") }
2020
}
2121

22-
/** The `execute` or `executeOnExecutor` method of Android `AsyncTask`. */
22+
/** The `execute` or `executeOnExecutor` method of Android's `AsyncTask` class. */
2323
class ExecuteAsyncTaskMethod extends Method {
2424
int paramIndex;
2525

@@ -35,23 +35,23 @@ class ExecuteAsyncTaskMethod extends Method {
3535
int getParamIndex() { result = paramIndex }
3636
}
3737

38-
/** The `doInBackground` method of Android `AsyncTask`. */
38+
/** The `doInBackground` method of Android's `AsyncTask` class. */
3939
class AsyncTaskRunInBackgroundMethod extends Method {
4040
AsyncTaskRunInBackgroundMethod() {
4141
this.getDeclaringType().getSourceDeclaration().getASourceSupertype*() instanceof AsyncTask and
4242
this.getName() = "doInBackground"
4343
}
4444
}
4545

46-
/** The service start method of Android context. */
46+
/** The service start method of Android's `Context` class. */
4747
class ContextStartServiceMethod extends Method {
4848
ContextStartServiceMethod() {
4949
this.getName() = ["startService", "startForegroundService"] and
5050
this.getDeclaringType().getASupertype*() instanceof TypeContext
5151
}
5252
}
5353

54-
/** The `onStartCommand` method of Android service. */
54+
/** The `onStartCommand` method of Android's `Service` class. */
5555
class ServiceOnStartCommandMethod extends Method {
5656
ServiceOnStartCommandMethod() {
5757
this.hasName("onStartCommand") and

java/ql/src/experimental/Security/CWE/CWE-200/AndroidFileIntentSource.qll

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import semmle.code.java.dataflow.FlowSources
55
import semmle.code.java.dataflow.TaintTracking2
66
import semmle.code.java.frameworks.android.Android
77

8-
/** The `startActivityForResult` method of Android `Activity`. */
8+
/** The `startActivityForResult` method of Android's `Activity` class. */
99
class StartActivityForResultMethod extends Method {
1010
StartActivityForResultMethod() {
1111
this.getDeclaringType().getASupertype*() instanceof AndroidActivity and
1212
this.getName() = "startActivityForResult"
1313
}
1414
}
1515

16-
/** Android class instance of `GET_CONTENT` intent. */
16+
/** An instance of `android.content.Intent` constructed passing `GET_CONTENT` to the constructor. */
1717
class GetContentIntent extends ClassInstanceExpr {
1818
GetContentIntent() {
1919
this.getConstructedType() instanceof TypeIntent and
@@ -28,7 +28,7 @@ class GetContentIntent extends ClassInstanceExpr {
2828
}
2929
}
3030

31-
/** Taint configuration for getting content intent. */
31+
/** Taint configuration that identifies `GET_CONTENT` `Intent` instances passed to `startActivityForResult`. */
3232
class GetContentIntentConfig extends TaintTracking2::Configuration {
3333
GetContentIntentConfig() { this = "GetContentIntentConfig" }
3434

@@ -56,8 +56,8 @@ class GetContentIntentConfig extends TaintTracking2::Configuration {
5656
}
5757
}
5858

59-
/** Android `Intent` input to request file loading. */
60-
class AndroidFileIntentInput extends LocalUserInput {
59+
/** A `GET_CONTENT` `Intent` instances that is passed to `startActivityForResult`. */
60+
class AndroidFileIntentInput extends DataFlow::Node {
6161
MethodAccess ma;
6262

6363
AndroidFileIntentInput() {
@@ -68,7 +68,7 @@ class AndroidFileIntentInput extends LocalUserInput {
6868
)
6969
}
7070

71-
/** The request code identifying a specific intent, which is to be matched in `onActivityResult()`. */
71+
/** The request code passed to `startActivityForResult`, which is to be matched in `onActivityResult()`. */
7272
int getRequestCode() { result = ma.getArgument(1).(CompileTimeConstantExpr).getIntValue() }
7373
}
7474

@@ -79,13 +79,3 @@ class OnActivityForResultMethod extends Method {
7979
this.getName() = "onActivityResult"
8080
}
8181
}
82-
83-
/** Input of Android activity result from the same application or another application. */
84-
class AndroidActivityResultInput extends DataFlow::Node {
85-
OnActivityForResultMethod m;
86-
87-
AndroidActivityResultInput() { this.asExpr() = m.getParameter(2).getAnAccess() }
88-
89-
/** The request code matching a specific intent request. */
90-
VarAccess getRequestCodeVar() { result = m.getParameter(0).getAnAccess() }
91-
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
<overview>
66
<p>The Android API allows to start an activity in another mobile application and receive a result back.
77
When starting an activity to retrieve a file from another application, missing input validation can
8-
lead to leaking of sensitive configuration file or user data because the intent is from the application
9-
itself that is allowed to access its protected data therefore bypassing the access control.
8+
lead to leaking of sensitive configuration file or user data because the intent could refer to paths
9+
which are accessible to the receiver application, but are intended to be application-private.
1010
</p>
1111
</overview>
1212

1313
<recommendation>
1414
<p>
15-
When loading file data from an activity of another application, validate that the file path is not its own
15+
When loading file data from an activity of another application, validate that the file path is not the receiver's
1616
protected directory, which is a subdirectory of the Android application directory <code>/data/data/</code>.
1717
</p>
1818
</recommendation>
1919

2020
<example>
2121
<p>
22-
The following examples show the bad situation and the good situation respectively. In bad situation, a
23-
file is loaded without path validation. In good situation, a file is loaded with path validation.
22+
The following examples show a bad situation and a good situation respectively. In the bad situation, a
23+
file is loaded without path validation. In the good situation, a file is loaded with path validation.
2424
</p>
2525
<sample src="LoadFileFromAppActivity.java" />
2626
</example>
@@ -33,6 +33,6 @@ Google:
3333
<li>
3434
CVE:
3535
<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-32695">CVE-2021-32695: File Sharing Flow Initiated by a Victim Leaks Sensitive Data to a Malicious App</a>.
36-
</li>
36+
</li>
3737
</references>
3838
</qhelp>

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Leaking sensitive Android file
3-
* @description Getting file intent from user input without path validation could leak arbitrary
3+
* @description Using a path specified in an Android Intent without validation could leak arbitrary
44
* Android configuration file and sensitive user data.
55
* @kind path-problem
66
* @id java/sensitive-android-file-leak
@@ -35,18 +35,17 @@ class AndroidFileLeakConfig extends TaintTracking::Configuration {
3535

3636
/**
3737
* Holds if `src` is a read of some Intent-typed variable guarded by a check like
38-
* `requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS`, where `requestCode` is the first
39-
* argument to `Activity.onActivityResult` and `REQUEST_CODE__SELECT_CONTENT_FROM_APPS` is
40-
* any request code in a call to `startActivityForResult(intent, code)`.
38+
* `requestCode == someCode`, where `requestCode` is the first
39+
* argument to `Activity.onActivityResult` and `someCode` is
40+
* any request code used in a call to `startActivityForResult(intent, someCode)`.
4141
*/
4242
override predicate isSource(DataFlow::Node src) {
4343
exists(
44-
AndroidActivityResultInput ai, AndroidFileIntentInput fi, ConditionBlock cb, EQExpr ee,
45-
CompileTimeConstantExpr cc, VarAccess intentVar
44+
OnActivityForResultMethod oafr, ConditionBlock cb, CompileTimeConstantExpr cc,
45+
VarAccess intentVar
4646
|
47-
cb.getCondition() = ee and
48-
ee.hasOperands(ai.getRequestCodeVar(), cc) and
49-
cc.getIntValue() = fi.getRequestCode() and
47+
cb.getCondition().(EQExpr).hasOperands(oafr.getParameter(0).getAnAccess(), cc) and
48+
cc.getIntValue() = any(AndroidFileIntentInput fi).getRequestCode() and
5049
intentVar.getType() instanceof TypeIntent and
5150
cb.controls(intentVar.getBasicBlock(), true) and
5251
src.asExpr() = intentVar

0 commit comments

Comments
 (0)