Skip to content

Commit c69a2be

Browse files
committed
Moved allowBackup query logic to allowsBackup pred
1 parent 5206c79 commit c69a2be

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,20 @@ class AndroidApplicationXmlElement extends XmlElement {
7979
* https://developer.android.com/guide/topics/data/autobackup
8080
*/
8181
predicate allowsBackup() {
82-
not exists(AndroidXmlAttribute attr |
83-
this.getAnAttribute() = attr and
84-
attr.getName() = "allowBackup" and
85-
attr.getValue() = "false"
82+
not this.getFile().(AndroidManifestXmlFile).isInBuildDirectory() and
83+
(
84+
// explicitly sets android:allowBackup="true"
85+
this.allowsBackupExplicitly()
86+
or
87+
// Manifest providing the main intent for an application, and does not explicitly
88+
// disallow the allowBackup attribute
89+
this.providesMainIntent() and
90+
// Check that android:allowBackup="false" is not present
91+
not exists(AndroidXmlAttribute attr |
92+
this.getAnAttribute() = attr and
93+
attr.getName() = "allowBackup" and
94+
attr.getValue() = "false"
95+
)
8696
)
8797
}
8898

@@ -91,7 +101,7 @@ class AndroidApplicationXmlElement extends XmlElement {
91101
*
92102
* https://developer.android.com/guide/topics/data/autobackup
93103
*/
94-
predicate allowsBackupExplicitly() {
104+
private predicate allowsBackupExplicitly() {
95105
exists(AndroidXmlAttribute attr |
96106
this.getAnAttribute() = attr and
97107
attr.getName() = "allowBackup" and
@@ -103,7 +113,7 @@ class AndroidApplicationXmlElement extends XmlElement {
103113
* Holds if the application element contains a child element which provides the
104114
* `android.intent.action.MAIN` intent.
105115
*/
106-
predicate providesMainIntent() {
116+
private predicate providesMainIntent() {
107117
exists(AndroidActivityXmlElement activity |
108118
activity = this.getAChild() and
109119
exists(AndroidIntentFilterXmlElement intentFilter |

java/ql/src/Security/CWE/CWE-312/AllowBackupAttributeEnabled.ql

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,5 @@ import java
1414
import semmle.code.xml.AndroidManifest
1515

1616
from AndroidApplicationXmlElement androidAppElem
17-
where
18-
not androidAppElem.getFile().(AndroidManifestXmlFile).isInBuildDirectory() and
19-
(
20-
// explicitly sets android:allowBackup=true
21-
androidAppElem.allowsBackupExplicitly()
22-
or
23-
// Manifest providing the main intent for an application, and does not explicitly
24-
// disallow the allowBackup attribute
25-
androidAppElem.providesMainIntent() and
26-
androidAppElem.allowsBackup()
27-
)
17+
where androidAppElem.allowsBackup()
2818
select androidAppElem, "The 'android:allowBackup' attribute is enabled."

0 commit comments

Comments
 (0)