|
| 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 | +} |
0 commit comments