Skip to content

Commit d3d712f

Browse files
committed
Remove Url#parse as a source
1 parent 5f4e8e3 commit d3d712f

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

java/ql/src/Security/CWE/CWE-094/ArbitraryAPKInstallation.ql

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SetDataSink extends DataFlow::ExprNode {
7171
/** A method that generates a URI. */
7272
class UriConstructorMethod extends Method {
7373
UriConstructorMethod() {
74-
this.hasQualifiedName("android.net", "Uri", ["parse", "fromFile", "fromParts"]) or
74+
this.hasQualifiedName("android.net", "Uri", [/*"parse",*/ "fromFile", "fromParts"]) or
7575
this.hasQualifiedName("androidx.core.content", "FileProvider", "getUriForFile")
7676
}
7777
}
@@ -110,6 +110,13 @@ class ApkConfiguration extends DataFlow::Configuration {
110110
}
111111
}
112112

113+
class SetActionMethod extends Method {
114+
SetActionMethod() {
115+
this.hasName("setAction") and
116+
this.getDeclaringType() instanceof TypeIntent
117+
}
118+
}
119+
113120
private class InstallPackageActionConfiguration extends TaintTracking3::Configuration {
114121
InstallPackageActionConfiguration() { this = "InstallPackageActionConfiguration" }
115122

@@ -123,10 +130,19 @@ private class InstallPackageActionConfiguration extends TaintTracking3::Configur
123130
) {
124131
state1 instanceof DataFlow::FlowStateEmpty and
125132
state2 = "hasPackageInstallAction" and
126-
exists(ConstructorCall cc |
127-
cc.getConstructedType() instanceof TypeIntent and
128-
node1.asExpr() = cc.getArgument(0) and
129-
node2.asExpr() = cc
133+
(
134+
exists(ConstructorCall cc |
135+
cc.getConstructedType() instanceof TypeIntent and
136+
node1.asExpr() = cc.getArgument(0) and
137+
node1.asExpr().getType() instanceof TypeString and
138+
node2.asExpr() = cc
139+
)
140+
or
141+
exists(MethodAccess ma |
142+
ma.getMethod() instanceof SetActionMethod and
143+
node1.asExpr() = ma.getArgument(0) and
144+
node2.asExpr() = ma.getQualifier()
145+
)
130146
)
131147
}
132148

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
edges
22
nodes
33
| APKInstallation.java:14:31:14:58 | fromFile(...) | semmle.label | fromFile(...) |
4-
| APKInstallation.java:21:31:21:44 | parse(...) | semmle.label | parse(...) |
5-
| APKInstallation.java:29:24:29:38 | parse(...) | semmle.label | parse(...) |
64
| APKInstallation.java:36:24:36:51 | fromFile(...) | semmle.label | fromFile(...) |
75
| APKInstallation.java:43:31:43:48 | fromFile(...) | semmle.label | fromFile(...) |
86
| APKInstallation.java:50:24:50:41 | fromFile(...) | semmle.label | fromFile(...) |
97
| APKInstallation.java:57:24:57:41 | fromFile(...) | semmle.label | fromFile(...) |
8+
| APKInstallation.java:70:24:70:41 | fromFile(...) | semmle.label | fromFile(...) |
109
subpaths
1110
#select
1211
| APKInstallation.java:14:31:14:58 | fromFile(...) | APKInstallation.java:14:31:14:58 | fromFile(...) | APKInstallation.java:14:31:14:58 | fromFile(...) | Arbitrary Android APK installation. |
13-
| APKInstallation.java:21:31:21:44 | parse(...) | APKInstallation.java:21:31:21:44 | parse(...) | APKInstallation.java:21:31:21:44 | parse(...) | Arbitrary Android APK installation. |
14-
| APKInstallation.java:29:24:29:38 | parse(...) | APKInstallation.java:29:24:29:38 | parse(...) | APKInstallation.java:29:24:29:38 | parse(...) | Arbitrary Android APK installation. |
1512
| APKInstallation.java:36:24:36:51 | fromFile(...) | APKInstallation.java:36:24:36:51 | fromFile(...) | APKInstallation.java:36:24:36:51 | fromFile(...) | Arbitrary Android APK installation. |
1613
| APKInstallation.java:43:31:43:48 | fromFile(...) | APKInstallation.java:43:31:43:48 | fromFile(...) | APKInstallation.java:43:31:43:48 | fromFile(...) | Arbitrary Android APK installation. |
1714
| APKInstallation.java:50:24:50:41 | fromFile(...) | APKInstallation.java:50:24:50:41 | fromFile(...) | APKInstallation.java:50:24:50:41 | fromFile(...) | Arbitrary Android APK installation. |
1815
| APKInstallation.java:57:24:57:41 | fromFile(...) | APKInstallation.java:57:24:57:41 | fromFile(...) | APKInstallation.java:57:24:57:41 | fromFile(...) | Arbitrary Android APK installation. |
16+
| APKInstallation.java:70:24:70:41 | fromFile(...) | APKInstallation.java:70:24:70:41 | fromFile(...) | APKInstallation.java:70:24:70:41 | fromFile(...) | Arbitrary Android APK installation. |

java/ql/test/query-tests/security/CWE-094/APKInstallation.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,19 @@ public void installAPK6(String path) {
5757
intent.setData(Uri.fromFile(file));
5858
startActivity(intent);
5959
}
60+
61+
public void openWebsite() {
62+
Intent intent = new Intent(Intent.ACTION_VIEW);
63+
intent.setData(Uri.parse("http://www.example.com"));
64+
startActivity(intent);
65+
}
66+
67+
public void otherIntent(File file) {
68+
Intent intent = new Intent(this, OtherActivity.class);
69+
intent.setAction(Intent.ACTION_VIEW);
70+
intent.setData(Uri.fromFile(file));
71+
}
72+
}
73+
74+
class OtherActivity extends Activity {
6075
}

0 commit comments

Comments
 (0)