Repository navigation
Expand file tree
/
Copy pathSensitiveAndroidFileLeak.ql
More file actions
86 lines (78 loc) · 3.64 KB
/
Copy pathSensitiveAndroidFileLeak.ql
File metadata and controls
86 lines (78 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @name Leaking sensitive Android file
* @description Using a path specified in an Android Intent without validation could leak arbitrary
* Android configuration file and sensitive user data.
* @kind path-problem
* @id java/sensitive-android-file-leak
* @problem.severity warning
* @tags security
* experimental
* external/cwe/cwe-200
*/
import java
import semmle.code.java.controlflow.Guards
deprecated import AndroidFileIntentSink
deprecated import AndroidFileIntentSource
deprecated import AndroidFileLeakFlow::PathGraph
private predicate startsWithSanitizer(Guard g, Expr e, boolean branch) {
exists(MethodCall ma |
g = ma and
ma.getMethod().hasName("startsWith") and
e = [ma.getQualifier(), ma.getQualifier().(MethodCall).getQualifier()] and
branch = false
)
}
deprecated module AndroidFileLeakConfig implements DataFlow::ConfigSig {
/**
* Holds if `src` is a read of some Intent-typed variable guarded by a check like
* `requestCode == someCode`, where `requestCode` is the first
* argument to `Activity.onActivityResult` and `someCode` is
* any request code used in a call to `startActivityForResult(intent, someCode)`.
*/
predicate isSource(DataFlow::Node src) {
exists(
OnActivityForResultMethod oafr, Guard g, CompileTimeConstantExpr cc, VarAccess intentVar
|
g.(ValueOrReferenceEqualsExpr).hasOperands(oafr.getParameter(0).getAnAccess(), cc) and
cc.getIntValue() = any(AndroidFileIntentInput fi).getRequestCode() and
intentVar.getType() instanceof TypeIntent and
g.controls(intentVar.getBasicBlock(), true) and
src.asExpr() = intentVar
)
}
/** Holds if it is a sink of file access in Android. */
predicate isSink(DataFlow::Node sink) { sink instanceof AndroidFileSink }
predicate isAdditionalFlowStep(DataFlow::Node prev, DataFlow::Node succ) {
exists(MethodCall aema, AsyncTaskRunInBackgroundMethod arm |
// fileAsyncTask.execute(params) will invoke doInBackground(params) of FileAsyncTask
aema.getQualifier().getType() = arm.getDeclaringType() and
aema.getMethod() instanceof ExecuteAsyncTaskMethod and
prev.asExpr() = aema.getArgument(aema.getMethod().(ExecuteAsyncTaskMethod).getParamIndex()) and
succ.asParameter() = arm.getParameter(0)
)
or
exists(MethodCall csma, ServiceOnStartCommandMethod ssm, ClassInstanceExpr ce |
// An intent passed to startService will later be passed to the onStartCommand event of the corresponding service
csma.getMethod() instanceof ContextStartServiceMethod and
ce.getConstructedType() instanceof TypeIntent and // Intent intent = new Intent(context, FileUploader.class);
ce.getArgument(1).(TypeLiteral).getReferencedType() = ssm.getDeclaringType() and
DataFlow::localExprFlow(ce, csma.getArgument(0)) and // context.startService(intent);
prev.asExpr() = csma.getArgument(0) and
succ.asParameter() = ssm.getParameter(0) // public int onStartCommand(Intent intent, int flags, int startId) {...} in FileUploader
)
}
predicate isBarrier(DataFlow::Node node) {
node = DataFlow::BarrierGuard<startsWithSanitizer/3>::getABarrierNode()
}
}
deprecated module AndroidFileLeakFlow = TaintTracking::Global<AndroidFileLeakConfig>;
deprecated query predicate problems(
DataFlow::Node sinkNode, AndroidFileLeakFlow::PathNode source, AndroidFileLeakFlow::PathNode sink,
string message1, DataFlow::Node sourceNode, string message2
) {
AndroidFileLeakFlow::flowPath(source, sink) and
sinkNode = sink.getNode() and
message1 = "Leaking arbitrary Android file from $@." and
sourceNode = source.getNode() and
message2 = "this user input"
}