Skip to content

Commit dd4e1d0

Browse files
Add tests and fix issues
1 parent 10a3b3b commit dd4e1d0

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,23 @@ class AndroidEditableXmlElement extends AndroidLayoutXmlElement {
4646
string getInputType() { result = this.getAttribute("inputType").(AndroidXmlAttribute).getValue() }
4747
}
4848

49+
/** A `findViewById` or `requireViewById` method on `Activity` or `View`. */
50+
private class FindViewMethod extends Method {
51+
FindViewMethod() {
52+
hasQualifiedName("android.view", "View", ["findViewById", "requireViewById"])
53+
or
54+
exists(Method m |
55+
m.hasQualifiedName("android.app", "Activity", ["findViewById", "requireViewById"]) and
56+
this = m.getAnOverride*()
57+
)
58+
}
59+
}
60+
4961
/** Gets a use of the view that has the given id. */
5062
private Expr getAUseOfId(string id) {
5163
exists(string name, MethodAccess findView, NestedClass r_id, Field id_field |
5264
id = "@+id/" + name and
53-
findView
54-
.getMethod()
55-
.hasQualifiedName("android.view", "View", ["findViewById", "requireViewById"]) and
65+
findView.getMethod() instanceof FindViewMethod and
5666
r_id.getEnclosingType().hasName("R") and
5767
r_id.hasName("id") and
5868
id_field.getDeclaringType() = r_id and

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ this sensitive data may be leaked to other applications via the keyboard cache.<
1313

1414
<p>For input fields expected to accept sensitive information, an input type such as <code>"textNoSuggestions"</code> (or <code>"textPassword"</code> for a password)
1515
should be used to ensure that the input does not get stored in the keyboard cache.</p>
16-
16+
<p>The input type can also be set in code through <code>TextView.setInputType()</code> rather than declared through XML.</p>
1717
</recommendation>
1818
<example>
1919

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.example.test;
2+
3+
public final class R {
4+
public static final class id {
5+
public static final int test7_password = 1;
6+
public static final int test8_password = 2;
7+
}
8+
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
package com.example.test;
2+
import android.app.Activity;
3+
import android.os.Bundle;
14
import android.widget.EditText;
5+
import android.view.View;
6+
import android.text.InputType;
27

3-
class Test {}
8+
class Test extends Activity {
9+
public void onCreate(Bundle b) {
10+
EditText test7pw = findViewById(R.id.test7_password);
11+
test7pw.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
12+
13+
EditText test8pw = requireViewById(R.id.test8_password);
14+
test8pw.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
15+
}
16+
}

java/ql/test/query-tests/security/CWE-524/res/layout/Test.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@
2323
<!-- $hasResult --> <EditText
2424
android:id="@+id/test5_bank_account_name"
2525
android:inputType="textMultiLine"/>
26+
27+
<!-- $hasResult --> <EditText
28+
android:id="@+id/test6_password"/>
29+
30+
<EditText
31+
android:id="@+id/test7_password"/>
32+
33+
<EditText
34+
android:id="@+id/test8_password"/>
2635
</LinearLayout>

java/ql/test/stubs/google-android-9.0.0/android/app/Activity.java

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)