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
155 lines (145 loc) · 4.85 KB
/
ql.code-snippets
File metadata and controls
155 lines (145 loc) · 4.85 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
{
// 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 ${3:a thing}. */",
"private DataFlow::LocalSourceNode ${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 $3. */",
"DataFlow::Node $1() {",
" $1(DataFlow::TypeTracker::end()).flowsTo(result)",
"}"
],
"description": "Type tracking predicate",
},
"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\""
]
},
}