-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLocalThreadResourceAbuse.ql
More file actions
78 lines (68 loc) · 2.75 KB
/
Copy pathLocalThreadResourceAbuse.ql
File metadata and controls
78 lines (68 loc) · 2.75 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
/**
* @name Uncontrolled thread resource consumption from local input source
* @description Using user input directly to control a thread's sleep time could lead to
* performance problems or even resource exhaustion.
* @kind path-problem
* @id java/local-thread-resource-abuse
* @problem.severity recommendation
* @tags security
* external/cwe/cwe-400
*/
import java
deprecated import ThreadResourceAbuse
import semmle.code.java.dataflow.TaintTracking
import semmle.code.java.dataflow.FlowSources
deprecated import ThreadResourceAbuseFlow::PathGraph
/** The `getInitParameter` method of servlet or JSF. */
class GetInitParameter extends Method {
GetInitParameter() {
(
this.getDeclaringType()
.getAnAncestor()
.hasQualifiedName(javaxOrJakarta() + ".servlet",
["FilterConfig", "Registration", "ServletConfig", "ServletContext"]) or
this.getDeclaringType()
.getAnAncestor()
.hasQualifiedName(javaxOrJakarta() + ".faces.context", "ExternalContext")
) and
this.getName() = "getInitParameter"
}
}
/** An access to the `getInitParameter` method. */
class GetInitParameterAccess extends MethodCall {
GetInitParameterAccess() { this.getMethod() instanceof GetInitParameter }
}
/* Init parameter input of a Java EE web application. */
class InitParameterInput extends LocalUserInput {
InitParameterInput() { this.asExpr() instanceof GetInitParameterAccess }
}
/** Taint configuration of uncontrolled thread resource consumption from local user input. */
deprecated module ThreadResourceAbuseConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }
predicate isSink(DataFlow::Node sink) { sink instanceof PauseThreadSink }
predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
any(AdditionalValueStep r).step(pred, succ)
}
predicate isBarrier(DataFlow::Node node) {
exists(
MethodCall ma // Math.min(sleepTime, MAX_INTERVAL)
|
ma.getMethod().hasQualifiedName("java.lang", "Math", "min") and
node.asExpr() = ma.getAnArgument()
)
or
node instanceof LessThanSanitizer // if (sleepTime > 0 && sleepTime < 5000) { ... }
}
}
deprecated module ThreadResourceAbuseFlow = TaintTracking::Global<ThreadResourceAbuseConfig>;
deprecated query predicate problems(
DataFlow::Node sinkNode, ThreadResourceAbuseFlow::PathNode source,
ThreadResourceAbuseFlow::PathNode sink, string message1, DataFlow::Node sourceNode,
string message2
) {
ThreadResourceAbuseFlow::flowPath(source, sink) and
sinkNode = sink.getNode() and
message1 = "Possible uncontrolled resource consumption due to $@." and
sourceNode = source.getNode() and
message2 = "local user-provided value"
}