Repository navigation
Expand file tree
/
Copy pathConcepts.qll
More file actions
287 lines (235 loc) · 10.5 KB
/
Copy pathConcepts.qll
File metadata and controls
287 lines (235 loc) · 10.5 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/**
* Provides abstract classes representing generic concepts such as file system
* access or system command execution, for which individual framework libraries
* provide concrete subclasses.
*/
overlay[local?]
module;
import java
/**
* A module importing the frameworks that implement string matches,
* ensuring that they are visible to the concepts library.
*/
private module Frameworks {
private import semmle.code.java.JDK
private import semmle.code.java.frameworks.apache.Lang
private import semmle.code.java.frameworks.guava.Guava
private import semmle.code.java.frameworks.JavaxAnnotations
}
/**
* An expression that represents a regular expression match.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `RegexMatch::Range` instead.
*
* These are either method calls, which return `true` when there is a match, or
* annotations, which are considered to match if they are present.
*
* To use a `RegexMatch` as a barrier or sanitizer, instantiate
* `DataFlow::BarrierGuard`. Method-call matches act as ordinary control-flow
* barrier guards, while annotation matches are treated as direct barriers,
* since an annotation does not dominate the expression it constrains;
* `DataFlow::BarrierGuard` handles both, so callers need not distinguish the two.
*/
class RegexMatch extends Expr instanceof RegexMatch::Range {
/** Gets the expression for the regex being executed by this node. */
Expr getRegex() { result = super.getRegex() }
/** Gets an expression for the string to be searched or matched against. */
Expr getString() { result = super.getString() }
/** Gets an expression to be sanitized. */
Expr getASanitizedExpr() { result = [this.getString(), super.getAdditionalSanitizedExpr()] }
/**
* Gets the name of this regex match, typically the name of an executing
* method. This is used for nice alert messages and should include the
* type-qualified name if possible.
*/
string getName() { result = super.getName() }
}
/** Provides classes for modeling regular-expression execution APIs. */
module RegexMatch {
/**
* An expression that executes a regular expression.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `RegexMatch` instead.
*
* These are either method calls, which return `true` when there is a match, or
* annotations, which are considered to match if they are present.
*/
abstract class Range extends Expr {
/** Gets the expression for the regex being executed by this node. */
abstract Expr getRegex();
/** Gets an expression for the string to be searched or matched against. */
abstract Expr getString();
/** Gets an additional expression to be sanitized, if any. */
Expr getAdditionalSanitizedExpr() { none() }
/**
* Gets the name of this regex match, typically the name of an executing
* method. This is used for nice alert messages and should include the
* type-qualified name if possible.
*/
abstract string getName();
}
}
/**
* An expression that tests whether an input string contains a substring.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `StringSubstringMatch::Range` instead.
*/
class StringSubstringMatch extends Expr instanceof StringSubstringMatch::Range {
/** Gets the input string being tested. */
Expr getInputString() { result = super.getInputString() }
/** Gets the expression that specifies the substring. */
Expr getMatchExpression() { result = super.getMatchExpression() }
/** Gets an expression to be sanitized. */
Expr getASanitizedExpr() { result = [this.getInputString(), super.getAdditionalSanitizedExpr()] }
/** Holds if taking `branch` means that the input contains the substring. */
predicate hasSubstringOnBranch(boolean branch) { super.hasSubstringOnBranch(branch) }
/** Gets a descriptive name for this substring match. */
string getName() { result = super.getName() }
}
/** Provides classes for modeling substring-matching APIs. */
module StringSubstringMatch {
/** A range class for APIs that test whether an input contains a substring. */
abstract class Range extends Expr {
/** Gets the input string being tested. */
abstract Expr getInputString();
/** Gets the expression that specifies the substring. */
abstract Expr getMatchExpression();
/** Gets an additional expression to be sanitized, if any. */
Expr getAdditionalSanitizedExpr() { none() }
/** Holds if taking `branch` means that the input contains the substring. */
abstract predicate hasSubstringOnBranch(boolean branch);
/** Gets a descriptive name for this substring match. */
abstract string getName();
}
}
/**
* An expression that tests whether an input string contains characters from a
* character set.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `StringCharacterSetMatch::Range` instead.
*/
class StringCharacterSetMatch extends Expr instanceof StringCharacterSetMatch::Range {
/** Gets the input string being tested. */
Expr getInputString() { result = super.getInputString() }
/** Gets the expression that specifies the character set. */
Expr getMatchExpression() { result = super.getMatchExpression() }
/** Gets an expression to be sanitized. */
Expr getASanitizedExpr() { result = [this.getInputString(), super.getAdditionalSanitizedExpr()] }
/**
* Holds if taking `branch` means that the input contains at least one
* character from the match expression.
*/
predicate hasMatchingCharacterOnBranch(boolean branch) {
super.hasMatchingCharacterOnBranch(branch)
}
/** Gets a descriptive name for this character-set match. */
string getName() { result = super.getName() }
}
/** Provides classes for modeling character-set matching APIs. */
module StringCharacterSetMatch {
/**
* A range class for APIs that test whether an input contains characters from
* a character set.
*/
abstract class Range extends Expr {
/** Gets the input string being tested. */
abstract Expr getInputString();
/** Gets the expression that specifies the character set. */
abstract Expr getMatchExpression();
/** Gets an additional expression to be sanitized, if any. */
Expr getAdditionalSanitizedExpr() { none() }
/**
* Holds if taking `branch` means that the input contains at least one
* character from the match expression.
*/
abstract predicate hasMatchingCharacterOnBranch(boolean branch);
/** Gets a descriptive name for this character-set match. */
abstract string getName();
}
}
/**
* An expression that replaces every occurrence of a target in a string.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `StringReplacement::Range` instead.
*/
class StringReplacement extends Expr instanceof StringReplacement::Range {
/** Gets the input string whose contents are replaced. */
Expr getInputString() { result = super.getInputString() }
/** Gets the expression that identifies the content to replace. */
Expr getMatchExpression() { result = super.getMatchExpression() }
/** Gets the replacement expression. */
Expr getReplacement() { result = super.getReplacement() }
/** Holds if the match expression is interpreted as a regular expression. */
predicate matchExpressionIsRegex() { super.matchExpressionIsRegex() }
/** Holds if each character in the match expression is matched independently. */
predicate matchExpressionIsCharacterSet() { super.matchExpressionIsCharacterSet() }
/** Gets a descriptive name for this replacement operation. */
string getName() { result = super.getName() }
}
/** Provides classes for modeling string-replacement APIs. */
module StringReplacement {
/**
* An expression that replaces every occurrence of a target in a string.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `StringReplacement` instead.
*/
abstract class Range extends Expr {
/** Gets the input string whose contents are replaced. */
abstract Expr getInputString();
/** Gets the expression that identifies the content to replace. */
abstract Expr getMatchExpression();
/** Gets the replacement expression. */
abstract Expr getReplacement();
/** Holds if the match expression is interpreted as a regular expression. */
predicate matchExpressionIsRegex() { none() }
/** Holds if each character in the match expression is matched independently. */
predicate matchExpressionIsCharacterSet() { none() }
/** Gets a descriptive name for this replacement operation. */
abstract string getName();
}
}
/**
* An expression that removes every occurrence of a target from a string.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `StringRemoval::Range` instead.
*/
class StringRemoval extends Expr instanceof StringRemoval::Range {
/** Gets the input string whose contents are removed. */
Expr getInputString() { result = super.getInputString() }
/** Gets the expression that identifies the content to remove. */
Expr getMatchExpression() { result = super.getMatchExpression() }
/** Holds if the match expression is interpreted as a regular expression. */
predicate matchExpressionIsRegex() { super.matchExpressionIsRegex() }
/** Holds if each character in the match expression is matched independently. */
predicate matchExpressionIsCharacterSet() { super.matchExpressionIsCharacterSet() }
/** Gets a descriptive name for this removal operation. */
string getName() { result = super.getName() }
}
/** Provides classes for modeling string-removal APIs. */
module StringRemoval {
/**
* An expression that removes every occurrence of a target from a string.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `StringRemoval` instead.
*/
abstract class Range extends Expr {
/** Gets the input string whose contents are removed. */
abstract Expr getInputString();
/** Gets the expression that identifies the content to remove. */
abstract Expr getMatchExpression();
/** Holds if the match expression is interpreted as a regular expression. */
predicate matchExpressionIsRegex() { none() }
/** Holds if each character in the match expression is matched independently. */
predicate matchExpressionIsCharacterSet() { none() }
/** Gets a descriptive name for this removal operation. */
abstract string getName();
}
}