Skip to content

Commit 94075ef

Browse files
Fix FPs - consider flow through fields when determining whether a view is masked, and find more instances of findViewById.
1 parent 8d20162 commit 94075ef

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

java/ql/lib/semmle/code/java/frameworks/android/Layout.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ class AndroidEditableXmlElement extends AndroidLayoutXmlElement {
4040
/** A `findViewById` or `requireViewById` method on `Activity` or `View`. */
4141
private class FindViewMethod extends Method {
4242
FindViewMethod() {
43-
this.hasQualifiedName("android.view", "View", ["findViewById", "requireViewById"])
44-
or
45-
exists(Method m |
46-
m.hasQualifiedName("android.app", "Activity", ["findViewById", "requireViewById"]) and
47-
this = m.getAnOverride*()
43+
exists(Method m | this.getAnOverride*() = m |
44+
m.hasQualifiedName("android.app", "Activity", ["findViewById", "requireViewById"])
45+
or
46+
m.hasQualifiedName("android.view", "View", ["findViewById", "requireViewById"])
47+
or
48+
m.hasQualifiedName("android.app", "Dialog", ["findViewById", "requireViewById"])
4849
)
4950
}
5051
}
5152

5253
/** Gets a use of the view that has the given id. (i.e. from a call to a method like `findViewById`) */
5354
MethodCall getAUseOfViewWithId(string id) {
5455
exists(string name, NestedClass r_id, Field id_field |
55-
id = "@+id/" + name and
56+
id = ["@+id/", "@id/"] + name and
5657
result.getMethod() instanceof FindViewMethod and
5758
r_id.getEnclosingType().hasName("R") and
5859
r_id.hasName("id") and

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,30 @@ private module TextFieldTrackingConfig implements DataFlow::ConfigSig {
7070
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
7171
}
7272

73-
/** Holds if the given may be masked. */
73+
/** A local flow step that also flows through access to fields containing `View`s */
74+
private predicate localViewFieldFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
75+
DataFlow::localFlowStep(node1, node2)
76+
or
77+
exists(Field f |
78+
f.getType().(Class).getASupertype*().hasQualifiedName("android.view", "View") and
79+
node1.asExpr() = f.getAnAccess().(FieldWrite).getASource() and
80+
node2.asExpr() = f.getAnAccess().(FieldRead)
81+
)
82+
}
83+
84+
/** Holds if data can flow from `node1` to `node2` with local flow steps as well as flow through fields containing `View`s */
85+
private predicate localViewFieldFlow(DataFlow::Node node1, DataFlow::Node node2) {
86+
localViewFieldFlowStep*(node1, node2)
87+
}
88+
89+
/** Holds if data can flow from `e1` to `e2` with local flow steps as well as flow through fields containing `View`s */
90+
private predicate localViewFieldExprFlow(Expr e1, Expr e2) {
91+
localViewFieldFlow(DataFlow::exprNode(e1), DataFlow::exprNode(e2))
92+
}
93+
94+
/** Holds if the given view may be properly masked. */
7495
private predicate viewIsMasked(AndroidLayoutXmlElement view) {
75-
DataFlow::localExprFlow(getAUseOfViewWithId(view.getId()), any(MaskCall mcall).getQualifier())
96+
localViewFieldExprFlow(getAUseOfViewWithId(view.getId()), any(MaskCall mcall).getQualifier())
7697
or
7798
view.getAttribute("inputType")
7899
.(AndroidXmlAttribute)
@@ -83,10 +104,10 @@ private predicate viewIsMasked(AndroidLayoutXmlElement view) {
83104
["invisible", "gone"]
84105
}
85106

86-
/** Holds if the qualifier of `call` is also called with a method that may mask the information displayed. */
107+
/** Holds if the qualifier of `call` may be properly masked. */
87108
private predicate setTextCallIsMasked(SetTextCall call) {
88109
exists(AndroidLayoutXmlElement view |
89-
DataFlow::localExprFlow(getAUseOfViewWithId(view.getId()), call.getQualifier()) and
110+
localViewFieldExprFlow(getAUseOfViewWithId(view.getId()), call.getQualifier()) and
90111
viewIsMasked(view.getParent*())
91112
)
92113
}

0 commit comments

Comments
 (0)