Skip to content

Commit 706858e

Browse files
Add test cases; fix the regex used
1 parent 85fe226 commit 706858e

File tree

7 files changed

+57
-1
lines changed

7 files changed

+57
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class AndroidEditableXmlElement extends XmlElement {
3333

3434
/** Gets a regex inidcating that an input field may contain sensitive data. */
3535
private string getInputSensitiveInfoRegex() {
36-
result = [getCommonSensitiveInfoRegex(), "(?i).*(bank|credit|debit|security).*"]
36+
result =
37+
[
38+
getCommonSensitiveInfoRegex(),
39+
"(?i).*(bank|credit|debit|(pass(wd|word|code|phrase))|security).*"
40+
]
3741
}
3842

3943
/** Holds if input using the given input type may be stored in the keyboard cache. */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
todo
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.example.test">
5+
</manifest>

java/ql/test/query-tests/security/CWE-524/SensitiveKeyboardCache.expected

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java
2+
import semmle.code.java.security.SensitiveKeyboardCacheQuery
3+
import TestUtilities.InlineExpectationsTest
4+
5+
class SensitiveKeyboardCacheTest extends InlineExpectationsTest {
6+
SensitiveKeyboardCacheTest() { this = "SensitiveKeyboardCacheTest" }
7+
8+
override string getARelevantTag() { result = "hasResult" }
9+
10+
override predicate hasActualResult(Location loc, string element, string tag, string value) {
11+
exists(AndroidEditableXmlElement el |
12+
el = getASensitiveCachedInput() and
13+
loc = el.getLocation() and
14+
element = el.toString() and
15+
tag = "hasResult" and
16+
value = ""
17+
)
18+
}
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Test {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto">
5+
6+
7+
<!-- $hasResult --> <EditText
8+
android:id="@+id/test1_password"
9+
android:inputType="text"/>
10+
11+
<EditText
12+
android:id="@+id/test2_safe"
13+
android:inputType="text"/>
14+
15+
<EditText
16+
android:id="@+id/test3_password"
17+
android:inputType="textNoSuggestions"/>
18+
19+
<EditText
20+
android:id="@+id/test4_password"
21+
android:inputType="textPassword"/>
22+
23+
<!-- $hasResult --> <EditText
24+
android:id="@+id/test5_bank_account_name"
25+
android:inputType="textMultiLine"/>
26+
</LinearLayout>

0 commit comments

Comments
 (0)