Skip to content

Commit 359d703

Browse files
More precise layout xml handling
1 parent f48b57c commit 359d703

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,40 @@ private class AndroidLayoutXmlFile extends XmlFile {
99
AndroidLayoutXmlFile() { this.getRelativePath().matches("%/res/layout/%.xml") }
1010
}
1111

12-
/** An XML element that represents an editable text field. */
13-
class AndroidEditableXmlElement extends XmlElement {
14-
AndroidXmlAttribute inputType;
12+
/** A component declared in an Android layout file. */
13+
class AndroidLayoutXmlElement extends XmlElement {
1514
AndroidXmlAttribute id;
1615

17-
AndroidEditableXmlElement() {
16+
AndroidLayoutXmlElement() {
1817
this.getFile() instanceof AndroidLayoutXmlFile and
19-
inputType = this.getAnAttribute() and
20-
inputType.getName() = "inputType" and
21-
id = this.getAnAttribute() and
22-
id.getName() = "id"
18+
id = this.getAttribute("id")
2319
}
2420

25-
/** Gets the input type of this field. */
26-
string getInputType() { result = inputType.getValue() }
27-
28-
/** Gets the ID of this field. */
21+
/** Gets the ID of this component. */
2922
string getId() { result = id.getValue() }
23+
24+
/** Gets the class of this component. */
25+
Class getClass() {
26+
this.getName() = "view" and
27+
this.getAttribute("class").getValue() = result.getQualifiedName()
28+
or
29+
this.getName() = result.getQualifiedName()
30+
or
31+
result.hasQualifiedName(["android.widget", "android.view"], this.getName())
32+
}
33+
}
34+
35+
/** An XML element that represents an editable text field. */
36+
class AndroidEditableXmlElement extends AndroidLayoutXmlElement {
37+
AndroidEditableXmlElement() {
38+
exists(Class editText |
39+
editText.hasQualifiedName("android.widget", "EditText") and
40+
editText = this.getClass().getASourceSupertype*()
41+
)
42+
}
43+
44+
/** Gets the input type of this field, if any. */
45+
string getInputType() { result = this.getAttribute("inputType").(AndroidXmlAttribute).getValue() }
3046
}
3147

3248
/** Gets a regex indicating that an input field may contain sensitive data. */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
import android.widget.EditText;
2+
13
class Test {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/google-android-9.0.0

0 commit comments

Comments
 (0)