forked from github/securitylab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnsafeReflection.ql
More file actions
54 lines (45 loc) · 1.69 KB
/
UnsafeReflection.ql
File metadata and controls
54 lines (45 loc) · 1.69 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
/**
* @name Unsafe reflection
* @description External input with reflection to select which classes to use
* @kind reflection
* @problem.severity warning
* @precision medium
* @id java/unsafe-reflection
* @tags security
* external/cwe/cwe-470
*/
import java
import semmle.code.java.dataflow.FlowSources
import DataFlow::PathGraph
class ClassFornameMethod extends Method {
ClassFornameMethod() {
this.getDeclaringType().getSourceDeclaration().hasQualifiedName("java.lang", "Class") and
this.hasName("forName")
}
}
class ArgumentToReflection extends Expr {
ArgumentToReflection() {
exists(MethodAccess ma, Method method |
ma.getArgument(0) = this and
method = ma.getMethod() and
method instanceof ClassFornameMethod
)
}
}
class StringArgumentToReflection extends ArgumentToReflection {
StringArgumentToReflection() { this.getType() instanceof TypeString }
}
class UnsafeReflectionConfig extends TaintTracking::Configuration {
UnsafeReflectionConfig() { this = "UnsafeReflectionConfig" }
override predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }
override predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof ArgumentToReflection }
override predicate isSanitizer(DataFlow::Node node) {
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
}
}
from
DataFlow::PathNode source, DataFlow::PathNode sink, UnsafeReflectionConfig conf,
StringArgumentToReflection reflectionArg
where conf.hasFlowPath(source, sink) and sink.getNode().asExpr() = reflectionArg
select reflectionArg, source, sink, "$@ flows to here and is used in reflection", source.getNode(),
"User controlled value"