Skip to content

Commit 5347770

Browse files
committed
Update Android app detection
1 parent 9c82966 commit 5347770

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,24 @@
55
import java
66
private import semmle.code.xml.AndroidManifest
77

8-
/** Holds if this database is of an Android application. */
9-
predicate isAndroid() { exists(AndroidManifestXmlFile m) }
8+
/**
9+
* There is an android manifest file which defines an activity, service or
10+
* content provider (so it corresponds to an android application rather than a
11+
* library), and `file` is in a subfolder of the folder that contains it.
12+
*/
13+
predicate inAndroidApplication(File file) {
14+
file.isSourceFile() and
15+
exists(AndroidComponentXmlElement acxe, AndroidManifestXmlFile amxf |
16+
amxf.getManifestElement().getApplicationElement().getAComponentElement() = acxe and
17+
(
18+
acxe instanceof AndroidActivityXmlElement or
19+
acxe instanceof AndroidServiceXmlElement or
20+
acxe instanceof AndroidProviderXmlElement
21+
)
22+
|
23+
file.getParentContainer+() = amxf.getParentContainer()
24+
)
25+
}
1026

1127
/**
1228
* Gets a reflexive/transitive superType

java/ql/lib/semmle/code/java/security/AndroidCertificatePinningQuery.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.frameworks.Networking
77
import semmle.code.java.security.Encryption
88
import semmle.code.java.security.HttpsUrls
9-
private import semmle.code.java.frameworks.android.Android as Android
9+
private import semmle.code.java.frameworks.android.Android
1010

1111
/** An Android Network Security Configuration XML file. */
1212
class AndroidNetworkSecurityConfigFile extends XmlFile {
@@ -21,11 +21,11 @@ class AndroidNetworkSecurityConfigFile extends XmlFile {
2121
}
2222

2323
/**
24-
* DEPRECATED. Use `semmle.code.java.frameworks.android.Android::isAndroid` instead.
24+
* DEPRECATED. Use `semmle.code.java.frameworks.android.Android::inAndroidApplication` instead.
2525
*
26-
* Holds if this database is of an Android application.
26+
* Holds if this database contains an Android manifest file.
2727
*/
28-
deprecated predicate isAndroid() { Android::isAndroid() }
28+
deprecated predicate isAndroid() { exists(AndroidManifestXmlFile m) }
2929

3030
/** Holds if the given domain name is trusted by the Network Security Configuration XML file. */
3131
private predicate trustedDomainViaXml(string domainName) {
@@ -127,7 +127,7 @@ private module UntrustedUrlFlow = TaintTracking::Global<UntrustedUrlConfig>;
127127

128128
/** Holds if `node` is a network communication call for which certificate pinning is not implemented. */
129129
predicate missingPinning(MissingPinningSink node, string domain) {
130-
Android::isAndroid() and
130+
inAndroidApplication(node.getLocation().getFile()) and
131131
exists(DataFlow::Node src | UntrustedUrlFlow::flow(src, node) |
132132
if trustedDomain(_) then domain = getDomain(src.asExpr()) else domain = ""
133133
)

java/ql/lib/semmle/code/java/security/CleartextStorageAndroidFilesystemQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private import semmle.code.java.frameworks.android.Android
1414
private class AndroidFilesystemCleartextStorageSink extends CleartextStorageSink {
1515
AndroidFilesystemCleartextStorageSink() {
1616
filesystemInput(_, this.asExpr()) and
17-
isAndroid()
17+
inAndroidApplication(this.getLocation().getFile())
1818
}
1919
}
2020

0 commit comments

Comments
 (0)