-
Notifications
You must be signed in to change notification settings - Fork 5
/
exercise8.ql
61 lines (53 loc) · 1.93 KB
/
exercise8.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
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Exercise 8: Combine your solutions from the previous exercise into a final solution.
*
* @name XWiki ratings SQLi
* @description SQL injection vulnerability in XWiki's ratings component. Disable the component or upgrade to resolve the issue.
* @id java/cve-2021-21380
* @kind path-problem
* @problem.severity error
* @precision high
* @tags security external/cwe/cwe-89
*/
import java
import semmle.code.java.dataflow.TaintTracking
import semmle.code.java.dataflow.FlowSources
import semmle.code.java.security.SqlInjectionQuery
import QueryInjectionFlow::PathGraph
module XWiki {
class Component extends Class {
Component() {
this.getAnAnnotation()
.getType()
.hasQualifiedName("org.xwiki.component.annotation", "Component")
}
}
class ScriptComponent extends Component {
ScriptComponent() { this.getASupertype().hasName("ScriptService") }
}
class ScriptComponentMethodParameterSource extends RemoteFlowSource {
ScriptComponentMethodParameterSource() {
exists(ScriptComponent scriptComponent, Method apiMethod |
scriptComponent.getAMethod() = apiMethod and
apiMethod.isPublic() and
apiMethod.getAParameter() = this.asParameter()
)
}
override string getSourceType() { result = "XWiki component method parameter" }
}
class StorageInterface extends Interface {
StorageInterface() { this.hasQualifiedName("com.xpn.xwiki.store", "XWikiStoreInterface") }
}
class DataStoreSink extends QueryInjectionSink {
DataStoreSink() {
exists(StorageInterface storeInterface, MethodCall storeCall |
storeCall.getQualifier().getType() = storeInterface
|
storeCall.getAnArgument() = this.asExpr()
)
}
}
}
from QueryInjectionFlow::PathNode source, QueryInjectionFlow::PathNode sink
where QueryInjectionFlow::flowPath(source, sink)
select sink, source, sink, "Possible query injection from $@", source.getNode(), "source"