Skip to content

Commit 5dd0add

Browse files
Add sensitive text flow query
1 parent aeae208 commit 5dd0add

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,38 @@ private module NotificationTrackingConfig implements DataFlow::ConfigSig {
2020

2121
/** Taint tracking flow for sensitive data flowing to system notifications. */
2222
module NotificationTracking = TaintTracking::Global<NotificationTrackingConfig>;
23+
24+
/** A call to a method that sets the text of a `TextView`. */
25+
private class SetTextCall extends MethodCall {
26+
SetTextCall() {
27+
this.getMethod()
28+
.getAnOverride*()
29+
.hasQualifiedName("android.widget", "TextView", ["append", "setText", "setHint"]) and
30+
(
31+
this.getMethod()
32+
.getParameter(0)
33+
.getType()
34+
.(RefType)
35+
.hasQualifiedName("java.lang", "CharSequence")
36+
or
37+
this.getMethod().getParameter(0).getType().(Array).getElementType() instanceof CharacterType
38+
)
39+
}
40+
41+
/** Gets the string argument of this call. */
42+
Expr getStringArgument() { result = this.getArgument(0) }
43+
}
44+
45+
/** A configuration for tracking sensitive information to text fields. */
46+
private module TextFieldTrackingConfig implements DataFlow::ConfigSig {
47+
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof SensitiveExpr }
48+
49+
predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(SetTextCall s).getStringArgument() }
50+
51+
predicate isBarrier(DataFlow::Node node) {
52+
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
53+
}
54+
}
55+
56+
/** Taint tracking flow for sensitive data flowing to text fields. */
57+
module TextFieldTracking = TaintTracking::Global<NotificationTrackingConfig>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Exposure of sensitive information to UI text fields.
3+
* @id java/android/sensitive-text
4+
* @kind path-problem
5+
* @description Sensitive information ... TODO
6+
* @problem.severity warning
7+
* @precision medium
8+
* @security-severity 6.5
9+
* @tags security
10+
* external/cwe/cwe-200
11+
*/
12+
13+
import java
14+
import java
15+
import semmle.code.java.security.SensitiveUiQuery
16+
import TextFieldTracking::PathGraph
17+
18+
from TextFieldTracking::PathNode source, TextFieldTracking::PathNode sink
19+
where NotificationTracking::flowPath(source, sink)
20+
select sink, source, sink, "This $@ is exposed in a text view.", source, "sensitive information"

0 commit comments

Comments
 (0)