Skip to content

Commit dad4a40

Browse files
committed
Add support for android:allowBackup default value
The default value of `android:allowBackup` is `true`. Added support for detecting if the default value is used.
1 parent 6509426 commit dad4a40

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ class AndroidApplicationXmlElement extends XmlElement {
7474
predicate requiresPermissions() { this.getAnAttribute().(AndroidPermissionXmlAttribute).isFull() }
7575

7676
/**
77-
* Holds if this application element has the attribute `android:allowBackup` set to `true`.
77+
* Holds if this application element enables the `android:allowBackup` attribute.
78+
*
79+
* https://developer.android.com/guide/topics/data/autobackup
7880
*/
7981
predicate allowsBackup() {
80-
exists(AndroidXmlAttribute attr |
82+
// The default value for the attribute `android:allowBackup` is `true`.
83+
// Therefore we also check if it is not present.
84+
not exists(AndroidXmlAttribute attr |
8185
this.getAnAttribute() = attr and
8286
attr.getName() = "allowBackup" and
83-
attr.getValue() = "true"
87+
attr.getValue() = "false"
8488
)
8589
}
8690
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ from AndroidApplicationXmlElement androidAppElem
1717
where
1818
androidAppElem.allowsBackup() and
1919
androidAppElem.getFile().(AndroidManifestXmlFile).isInBuildDirectory()
20-
select androidAppElem.getAttribute("allowBackup"), "The 'android:allowBackup' attribute is enabled."
20+
select androidAppElem, "The 'android:allowBackup' attribute is enabled."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest ... >
2+
<!-- BAD: no 'android:allowBackup' set, defaults to 'true' -->
3+
<application>
4+
<activity ... >
5+
</activity>
6+
</application>
7+
</manifest>

0 commit comments

Comments
 (0)