Skip to content

Commit 85fe226

Browse files
Add sensitive keyboard cache query
1 parent 7bf55c5 commit 85fe226

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/** Definitions for the keyboard cache query */
2+
3+
import java
4+
import semmle.code.xml.XML
5+
import semmle.code.java.security.SensitiveActions
6+
7+
/** An Android Layout XML file. */
8+
class AndroidLayoutXmlFile extends XmlFile {
9+
AndroidLayoutXmlFile() { this.getAbsolutePath().matches("%/res/layout/%.xml") }
10+
}
11+
12+
/** An XML element that represents an editable text field. */
13+
class AndroidEditableXmlElement extends XmlElement {
14+
XmlAttribute inputType;
15+
XmlAttribute id;
16+
17+
AndroidEditableXmlElement() {
18+
this.getFile() instanceof AndroidLayoutXmlFile and
19+
inputType = this.getAnAttribute() and
20+
inputType.getNamespace().getPrefix() = "android" and
21+
inputType.getName() = "inputType" and
22+
id = this.getAnAttribute() and
23+
id.getNamespace().getPrefix() = "android" and
24+
id.getName() = "id"
25+
}
26+
27+
/** Gets the input type of this field. */
28+
string getInputType() { result = inputType.getValue() }
29+
30+
/** Gets the ID of this field. */
31+
string getId() { result = id.getValue() }
32+
}
33+
34+
/** Gets a regex inidcating that an input field may contain sensitive data. */
35+
private string getInputSensitiveInfoRegex() {
36+
result = [getCommonSensitiveInfoRegex(), "(?i).*(bank|credit|debit|security).*"]
37+
}
38+
39+
/** Holds if input using the given input type may be stored in the keyboard cache. */
40+
bindingset[ty]
41+
private predicate inputTypeCached(string ty) {
42+
ty.matches("%text%") and
43+
not ty.regexpMatch("(?i).*(nosuggestions|password).*")
44+
}
45+
46+
/** Gets an input field whose contents may be sensitive and may be stored in the keyboard cache. */
47+
AndroidEditableXmlElement getASensitiveCachedInput() {
48+
result.getId().regexpMatch(getInputSensitiveInfoRegex()) and
49+
inputTypeCached(result.getInputType())
50+
}

java/ql/src/Security/CWE/CWE-524/SensitiveKeyboardCache.qhelp

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Android sensetive keyboard cache
3+
* @description Sensitive information should not be saved to the keyboard cache.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id java/android/debuggable-attribute-enabled
7+
* @tags security
8+
* external/cwe/cwe-489
9+
* @precision high
10+
*/
11+
12+
import java
13+
import semmle.code.java.security.SensitiveKeyboardCacheQuery
14+
15+
from AndroidEditableXmlElement el
16+
where el = getASensitiveCachedInput()
17+
select el, "This input field may contain sensitive information that is saved to the keyboard cache."

0 commit comments

Comments
 (0)