forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJaxRs.ql
More file actions
170 lines (167 loc) · 5.6 KB
/
JaxRs.ql
File metadata and controls
170 lines (167 loc) · 5.6 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import java
import semmle.code.java.frameworks.JaxWS
import semmle.code.java.security.XSS
import TestUtilities.InlineExpectationsTest
class JaxRsTest extends InlineExpectationsTest {
JaxRsTest() { this = "JaxRsTest" }
override string getARelevantTag() {
result =
[
"ResourceMethod", "RootResourceClass", "NonRootResourceClass",
"ResourceMethodOnResourceClass", "InjectableConstructor", "InjectableField",
"InjectionAnnotation", "ResponseDeclaration", "ResponseBuilderDeclaration",
"ClientDeclaration", "BeanParamConstructor", "MessageBodyReaderDeclaration",
"MessageBodyReaderReadFromCall", "MessageBodyReaderReadCall", "ProducesAnnotation",
"ConsumesAnnotation"
]
}
override predicate hasActualResult(Location location, string element, string tag, string value) {
tag = "ResourceMethod" and
exists(JaxRsResourceMethod resourceMethod |
resourceMethod.getLocation() = location and
element = resourceMethod.toString() and
if exists(resourceMethod.getProducesAnnotation())
then
value =
getContentTypeString(resourceMethod.getProducesAnnotation().getADeclaredContentTypeExpr()) and
value != ""
else
// Filter out empty strings that stem from using stubs.
// If we built the test against the real JAR then the field
// access against e.g. MediaType.APPLICATION_JSON wouldn't
// be a CompileTimeConstantExpr at all, whereas in the stubs
// it is and is defined empty.
value = ""
)
or
tag = "RootResourceClass" and
exists(JaxRsResourceClass resourceClass |
resourceClass.isRootResource() and
resourceClass.getLocation() = location and
element = resourceClass.toString() and
value = ""
)
or
tag = "NonRootResourceClass" and
exists(JaxRsResourceClass resourceClass |
not resourceClass.isRootResource() and
resourceClass.getLocation() = location and
element = resourceClass.toString() and
value = ""
)
or
tag = "ResourceMethodOnResourceClass" and
exists(JaxRsResourceMethod resourceMethod |
resourceMethod = any(JaxRsResourceClass ResourceClass).getAResourceMethod()
|
resourceMethod.getLocation() = location and
element = resourceMethod.toString() and
value = ""
)
or
tag = "InjectableConstructor" and
exists(Constructor cons |
cons = any(JaxRsResourceClass resourceClass).getAnInjectableConstructor()
|
cons.getLocation() = location and
element = cons.toString() and
value = ""
)
or
tag = "InjectableField" and
exists(Field field | field = any(JaxRsResourceClass resourceClass).getAnInjectableField() |
field.getLocation() = location and
element = field.toString() and
value = ""
)
or
tag = "InjectionAnnotation" and
exists(JaxRsInjectionAnnotation injectionAnnotation |
injectionAnnotation.getLocation() = location and
element = injectionAnnotation.toString() and
value = ""
)
or
tag = "ResponseDeclaration" and
exists(LocalVariableDecl decl |
decl.getType() instanceof JaxRsResponse and
decl.getLocation() = location and
element = decl.toString() and
value = ""
)
or
tag = "ResponseBuilderDeclaration" and
exists(LocalVariableDecl decl |
decl.getType() instanceof JaxRsResponseBuilder and
decl.getLocation() = location and
element = decl.toString() and
value = ""
)
or
tag = "ClientDeclaration" and
exists(LocalVariableDecl decl |
decl.getType() instanceof JaxRsClient and
decl.getLocation() = location and
element = decl.toString() and
value = ""
)
or
tag = "BeanParamConstructor" and
exists(JaxRsBeanParamConstructor cons |
cons.getLocation() = location and
element = cons.toString() and
value = ""
)
or
tag = "MessageBodyReaderDeclaration" and
exists(LocalVariableDecl decl |
decl.getType().(RefType).getSourceDeclaration() instanceof MessageBodyReader and
decl.getLocation() = location and
element = decl.toString() and
value = ""
)
or
tag = "MessageBodyReaderReadFromCall" and
exists(MethodAccess ma |
ma.getMethod() instanceof MessageBodyReaderReadFrom and
ma.getLocation() = location and
element = ma.toString() and
value = ""
)
or
tag = "MessageBodyReaderReadCall" and
exists(MethodAccess ma |
ma.getMethod() instanceof MessageBodyReaderRead and
ma.getLocation() = location and
element = ma.toString() and
value = ""
)
or
tag = "ProducesAnnotation" and
exists(JaxRSProducesAnnotation producesAnnotation |
producesAnnotation.getLocation() = location and
element = producesAnnotation.toString() and
value = getContentTypeString(producesAnnotation.getADeclaredContentTypeExpr()) and
value != ""
// Filter out empty strings that stem from using stubs.
// If we built the test against the real JAR then the field
// access against e.g. MediaType.APPLICATION_JSON wouldn't
// be a CompileTimeConstantExpr at all, whereas in the stubs
// it is and is defined empty.
)
or
tag = "ConsumesAnnotation" and
exists(JaxRSConsumesAnnotation consumesAnnotation |
consumesAnnotation.getLocation() = location and
element = consumesAnnotation.toString() and
value = ""
)
or
tag = "XssSink" and
exists(XssSink xssSink |
xssSink.getLocation() = location and
element = xssSink.toString() and
value = ""
)
}
}