-
Notifications
You must be signed in to change notification settings - Fork 0
/
CqlInjection.ql
49 lines (42 loc) · 1.66 KB
/
CqlInjection.ql
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
/**
* @name CQL query built from user-controlled sources
* @description Building a CQL query from user-controlled sources is vulnerable to insertion of
* malicious code by the user.
* @kind path-problem
* @problem.severity error
* @security-severity 8.8
* @precision high
* @id js/cap-sql-injection
* @tags security
*/
import javascript
import DataFlow::PathGraph
import semmle.javascript.security.dataflow.SqlInjectionCustomizations::SqlInjection
import advanced_security.javascript.frameworks.cap.CQL
import advanced_security.javascript.frameworks.cap.RemoteFlowSources
class CqlIConfiguration extends TaintTracking::Configuration {
CqlIConfiguration() { this = "CqlInjection" }
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
override predicate isSink(DataFlow::Node sink) { sink instanceof CQLSink }
override predicate isSanitizer(DataFlow::Node node) {
super.isSanitizer(node) or
node instanceof Sanitizer
}
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
//string concatenation in a clause arg taints the clause
exists(TaintedClause clause |
clause.getArgument() = pred.asExpr() and
clause.asExpr() = succ.asExpr()
)
or
//less precise, any concat in the alternative sql stmt construction techniques
exists(ParseCQLTaintedClause parse |
parse.getAnArgument() = pred and
parse = succ
)
}
}
from CqlIConfiguration sql, DataFlow::PathNode source, DataFlow::PathNode sink
where sql.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "This query depends on a $@.", source.getNode(),
"user-provided value"