Skip to content
Navigation Menu
{{ message }}
forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathql.code-snippets
More file actions
355 lines (342 loc) · 13.8 KB
/
Copy pathql.code-snippets
File metadata and controls
355 lines (342 loc) · 13.8 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{
// Place your python workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Has relative path": {
"scope": "ql",
"prefix": "has relative path",
"body": [
"exists($1.getLocation().getFile().getRelativePath())"
],
"description": "has relative path",
},
"Exists": {
"scope": "ql",
"prefix": "exists",
"body": [
"exists(${1:DataFlow::Node node} |",
" $2",
")"
],
"description": "Exists clause",
},
"Predicate": {
"scope": "ql",
"prefix": "predicate",
"body": [
"predicate ${1:isFoo}(${2:DataFlow::Node node}) {",
" ${3:any()}",
"}"
],
"description": "Predicate",
},
"Class": {
"scope": "ql",
"prefix": "class",
"body": [
"class ${1:MyClass} extends ${2:DataFlow::MethodCallNode} {",
" $1() { ${3:getMethodName() = \"foo\"} }",
"",
" DataFlow::Node ${4:getThing}() { result = ${5:getArgument(0)} }",
"}"
],
"description": "Class",
},
"Abstract class": {
"scope": "ql",
"prefix": "abstract class",
"body": [
"abstract class ${1:AdditionalThing} extends ${2:DataFlow::Node} {",
" abstract ${3:DataFlow::Node} ${4:getThing}($5);",
"}"
],
"description": "Class",
},
"Class::Range": {
"scope": "ql",
"prefix": "range class",
"body": [
"class ${1:MyClass} extends ${2:DataFlow::Node} {",
" $1::Range range;",
"",
" $1() { this = range }",
"",
" ${3:DataFlow::Node} ${4:getThing}() { result = range.$4() }",
"}",
"",
"module $1 {",
" abstract class Range extends $2 {",
" abstract $3 $4();",
" }",
"}",
],
"description": "Class with ::Range pattern",
},
"Class::Range delegate": {
"scope": "ql",
"prefix": "range delegate",
"body": [
"${1:DataFlow::Node} ${2:getThing}() { result = range.$2() }"
],
"description": "Predicate that delegates to range class",
},
"Type tracking predicate": {
"scope": "ql",
"prefix": "type tracking",
"body": [
"/** Gets a reference to a ${3:thing}. */",
"private DataFlow::Node ${1:myType}(DataFlow::TypeTracker t) {",
" t.start() and",
" result = ${2:value}",
" or",
" exists(DataFlow::TypeTracker t2 |",
" result = $1(t2).track(t2, t)",
" )",
"}",
"",
"/** Gets a reference to a ${3:thing}. */",
"DataFlow::Node $1() {",
" result = $1(DataFlow::TypeTracker::end())",
"}"
],
"description": "Type tracking predicate",
},
"Type tracking module": {
"scope": "ql",
"prefix": "type tracking module",
"body": [
"// ---------------------------------------------------------------------------",
"// ${1:modulename}",
"// ---------------------------------------------------------------------------",
"/** Gets a reference to the `$1` module. */",
"private DataFlow::Node $1(DataFlow::TypeTracker t) {",
" t.start() and",
" result = DataFlow::importNode(\"$1\")",
" or",
" exists(DataFlow::TypeTracker t2 | result = $1(t2).track(t2, t))",
"}",
"",
"/** Gets a reference to the `$1` module. */",
"DataFlow::Node $1() { result = $1(DataFlow::TypeTracker::end()) }",
"",
"/**",
" * Gets a reference to the attribute `attr_name` of the `$1` module.",
" * WARNING: Only holds for a few predefined attributes.",
" */",
"private DataFlow::Node $1_attr(DataFlow::TypeTracker t, string attr_name) {",
" attr_name in [\"${2:name}\"] and",
" (",
" t.start() and",
" result = DataFlow::importNode(\"$1\" + \".\" + attr_name)",
" or",
" t.startInAttr(attr_name) and",
" result = $1()",
" )",
" or",
" // Due to bad performance when using normal setup with `$1_attr(t2, attr_name).track(t2, t)`",
" // we have inlined that code and forced a join",
" exists(DataFlow::TypeTracker t2 |",
" exists(DataFlow::StepSummary summary |",
" $1_attr_first_join(t2, attr_name, result, summary) and",
" t = t2.append(summary)",
" )",
" )",
"}",
"",
"pragma[nomagic]",
"private predicate $1_attr_first_join(",
" DataFlow::TypeTracker t2, string attr_name, DataFlow::Node res, DataFlow::StepSummary summary",
") {",
" DataFlow::StepSummary::step($1_attr(t2, attr_name), res, summary)",
"}",
"",
"/**",
" * Gets a reference to the attribute `attr_name` of the `$1` module.",
" * WARNING: Only holds for a few predefined attributes.",
" */",
"private DataFlow::Node $1_attr(string attr_name) {",
" result = $1_attr(DataFlow::TypeTracker::end(), attr_name)",
"}",
"",
"/** Provides models for the `$1` module. */",
"module $1 {",
"",
"}",
],
"description": "Type tracking module",
},
"Type tracking module member": {
"scope": "ql",
"prefix": "type tracking module member",
"body": [
"/** Gets a reference to the `${1:module}.${2:member}` ${3:object/class}. */",
"private DataFlow::Node ${4:$2}(DataFlow::TypeTracker t) {",
" t.start() and",
" result = DataFlow::importNode(\"$1.$2\")",
" or",
" t.startInAttr(\"$2\") and",
" result = $1()",
" or",
" exists(DataFlow::TypeTracker t2 | result = $4(t2).track(t2, t))",
"}",
" ",
"/** Gets a reference to the `$1.$2` $3. */",
"DataFlow::Node $4() { result = $4(DataFlow::TypeTracker::end()) }",
],
"description": "Type tracking module member",
},
"Taint tracking configuration": {
"scope": "ql",
"prefix": "taint tracking",
"body": [
"/** @kind path-problem */",
"import python",
"import experimental.dataflow.DataFlow",
"import experimental.dataflow.TaintTracking",
"import experimental.semmle.python.Concepts",
"import experimental.dataflow.RemoteFlowSources",
"import DataFlow::PathGraph",
"class ${1:Config} extends TaintTracking::Configuration {",
" $1() { this = \"$1\" } ",
"",
" override predicate isSource(DataFlow::Node node) {",
" ${2:none()}",
" }",
"",
" override predicate isSink(DataFlow::Node node) {",
" ${3:none()}",
" }",
"}",
"",
"from $1 cfg, DataFlow::PathNode source, DataFlow::PathNode sink",
"where cfg.hasFlowPath(source, sink)",
"select sink, source, sink, \"taint from $@\", source.getNode(), \"here\""
]
},
"Type tracking submodule": {
"scope": "ql",
"prefix": "type tracking submodule",
"body": [
" // -------------------------------------------------------------------------",
" // ${1:parent}.${2:submodule}",
" // -------------------------------------------------------------------------",
" /** Gets a reference to the `$1.$2` module. */",
" DataFlow::Node $2() { result = $1_attr(\"$2\") }",
"",
" /** Provides models for the `$1.$2` module */",
" module $2 {",
" /**",
" * Gets a reference to the attribute `attr_name` of the `$1.$2` module.",
" * WARNING: Only holds for a few predefined attributes.",
" */",
" private DataFlow::Node $2_attr(DataFlow::TypeTracker t, string attr_name) {",
" attr_name in [\"$3\"] and",
" (",
" t.start() and",
" result = DataFlow::importNode(\"$1.$2\" + \".\" + attr_name)",
" or",
" t.startInAttr(attr_name) and",
" result = $2()",
" )",
" or",
" // Due to bad performance when using normal setup with `$2_attr(t2, attr_name).track(t2, t)`",
" // we have inlined that code and forced a join",
" exists(DataFlow::TypeTracker t2 |",
" exists(DataFlow::StepSummary summary |",
" $2_attr_first_join(t2, attr_name, result, summary) and",
" t = t2.append(summary)",
" )",
" )",
" }",
"",
" pragma[nomagic]",
" private predicate $2_attr_first_join(",
" DataFlow::TypeTracker t2, string attr_name, DataFlow::Node res,",
" DataFlow::StepSummary summary",
" ) {",
" DataFlow::StepSummary::step($2_attr(t2, attr_name), res, summary)",
" }",
"",
" /**",
" * Gets a reference to the attribute `attr_name` of the `$1.$2` module.",
" * WARNING: Only holds for a few predefined attributes.",
" */",
" private DataFlow::Node $2_attr(string attr_name) {",
" result = $2_attr(DataFlow::TypeTracker::end(), attr_name)",
" }",
" }",
],
"description": "Type tracking submodule",
},
"Type tracking class": {
"scope": "ql",
"prefix": "type tracking class",
"body": [
" /**",
" * Provides models for the `${1:module}.${2:classname}` class",
" *",
" * See ${6:apiref}.",
" */",
" module $2 {",
" /** Gets a reference to the `$1.$2` class. */",
" private DataFlow::Node classRef(DataFlow::TypeTracker t) {",
" t.start() and",
" result = ${4:module}_attr(\"$2\")",
" or",
" // TODO: remove/expand this part of the template as needed",
" // Handle `${5:toplevel}.$2` alias",
" t.start() and",
" result = $5_attr(\"$2\")",
" or",
" exists(DataFlow::TypeTracker t2 | result = classRef(t2).track(t2, t))",
" }",
"",
" /** Gets a reference to the `$1.$2` class. */",
" DataFlow::Node classRef() { result = classRef(DataFlow::TypeTracker::end()) }",
"",
" /**",
" * A source of instances of `$1.$2`, extend this class to model new instances.",
" *",
" * This can include instantiations of the class, return values from function",
" * calls, or a special parameter that will be set when functions are called by an external",
" * library.",
" *",
" * Use the predicate `$2::instance()` to get references to instances of `$1.$2`.",
" */",
" abstract class InstanceSource extends DataFlow::Node { }",
"",
" /** A direct instantiation of `$1.$2`. */",
" private class ClassInstantiation extends InstanceSource, DataFlow::CfgNode {",
" override CallNode node;",
"",
" ClassInstantiation() { node.getFunction() = classRef().asCfgNode() }",
" }",
"",
" /** Gets a reference to an instance of `$1.$2`. */",
" private DataFlow::Node instance(DataFlow::TypeTracker t) {",
" t.start() and",
" result instanceof InstanceSource",
" or",
" exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t))",
" }",
"",
" /** Gets a reference to an instance of `$1.$2`. */",
" DataFlow::Node instance() { result = instance(DataFlow::TypeTracker::end()) }",
" }",
],
"description": "Type tracking class",
},
}
You can’t perform that action at this time.
