Skip to content

Commit fdb7745

Browse files
committed
Sync files
1 parent 04de315 commit fdb7745

File tree

2 files changed

+206
-164
lines changed

2 files changed

+206
-164
lines changed

javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 103 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* INTERNAL use only. This is an experimental API subject to change without notice.
33
*
4-
* Provides classes and predicates for dealing with flow models specified in CSV format.
4+
* Provides classes and predicates for dealing with flow models specified in extensible predicates.
55
*
6-
* The CSV specification has the following columns:
6+
* The extensible predicates have the following columns:
77
* - Sources:
8-
* `type; path; kind`
8+
* `type, path, kind`
99
* - Sinks:
10-
* `type; path; kind`
10+
* `type, path, kind`
1111
* - Summaries:
12-
* `type; path; input; output; kind`
12+
* `type, path, input, output, kind`
1313
* - Types:
14-
* `type1; type2; path`
14+
* `type1, type2, path`
1515
*
1616
* The interpretation of a row is similar to API-graphs with a left-to-right
1717
* reading.
@@ -80,7 +80,7 @@ module ModelInput {
8080
*
8181
* Extend this class to add additional source definitions.
8282
*/
83-
class SourceModelCsv extends Unit {
83+
deprecated class SourceModelCsv extends Unit {
8484
/**
8585
* Holds if `row` specifies a source definition.
8686
*
@@ -93,15 +93,15 @@ module ModelInput {
9393
*
9494
* The kind `remote` represents a general remote flow source.
9595
*/
96-
abstract predicate row(string row);
96+
abstract deprecated predicate row(string row);
9797
}
9898

9999
/**
100100
* A unit class for adding additional sink model rows.
101101
*
102102
* Extend this class to add additional sink definitions.
103103
*/
104-
class SinkModelCsv extends Unit {
104+
deprecated class SinkModelCsv extends Unit {
105105
/**
106106
* Holds if `row` specifies a sink definition.
107107
*
@@ -112,15 +112,15 @@ module ModelInput {
112112
* indicates that the value at `(type, path)` should be seen as a sink
113113
* of the given `kind`.
114114
*/
115-
abstract predicate row(string row);
115+
abstract deprecated predicate row(string row);
116116
}
117117

118118
/**
119119
* A unit class for adding additional summary model rows.
120120
*
121121
* Extend this class to add additional flow summary definitions.
122122
*/
123-
class SummaryModelCsv extends Unit {
123+
deprecated class SummaryModelCsv extends Unit {
124124
/**
125125
* Holds if `row` specifies a summary definition.
126126
*
@@ -134,15 +134,15 @@ module ModelInput {
134134
* `kind` should be either `value` or `taint`, for value-preserving or taint-preserving steps,
135135
* respectively.
136136
*/
137-
abstract predicate row(string row);
137+
abstract deprecated predicate row(string row);
138138
}
139139

140140
/**
141141
* A unit class for adding additional type model rows.
142142
*
143143
* Extend this class to add additional type definitions.
144144
*/
145-
class TypeModelCsv extends Unit {
145+
deprecated class TypeModelCsv extends Unit {
146146
/**
147147
* Holds if `row` specifies a type definition.
148148
*
@@ -152,7 +152,7 @@ module ModelInput {
152152
* ```
153153
* indicates that `(type2, path)` should be seen as an instance of `type1`.
154154
*/
155-
abstract predicate row(string row);
155+
abstract deprecated predicate row(string row);
156156
}
157157

158158
/**
@@ -187,7 +187,7 @@ module ModelInput {
187187
/**
188188
* A unit class for adding additional type variable model rows.
189189
*/
190-
class TypeVariableModelCsv extends Unit {
190+
deprecated class TypeVariableModelCsv extends Unit {
191191
/**
192192
* Holds if `row` specifies a path through a type variable.
193193
*
@@ -197,7 +197,7 @@ module ModelInput {
197197
* ```
198198
* means `path` can be substituted for a token `TypeVar[name]`.
199199
*/
200-
abstract predicate row(string row);
200+
abstract deprecated predicate row(string row);
201201
}
202202
}
203203

@@ -216,27 +216,88 @@ abstract class TestAllModels extends Unit { }
216216
* does not preserve empty trailing substrings.
217217
*/
218218
bindingset[result]
219-
private string inversePad(string s) { s = result + ";dummy" }
219+
deprecated private string inversePad(string s) { s = result + ";dummy" }
220220

221-
private predicate sourceModel(string row) { any(SourceModelCsv s).row(inversePad(row)) }
221+
deprecated private predicate sourceModel(string row) { any(SourceModelCsv s).row(inversePad(row)) }
222222

223-
private predicate sinkModel(string row) { any(SinkModelCsv s).row(inversePad(row)) }
223+
deprecated private predicate sinkModel(string row) { any(SinkModelCsv s).row(inversePad(row)) }
224224

225-
private predicate summaryModel(string row) { any(SummaryModelCsv s).row(inversePad(row)) }
225+
deprecated private predicate summaryModel(string row) {
226+
any(SummaryModelCsv s).row(inversePad(row))
227+
}
228+
229+
deprecated private predicate typeModel(string row) { any(TypeModelCsv s).row(inversePad(row)) }
230+
231+
deprecated private predicate typeVariableModel(string row) {
232+
any(TypeVariableModelCsv s).row(inversePad(row))
233+
}
234+
235+
private class DeprecationAdapter extends Unit {
236+
abstract predicate sourceModel(string type, string path, string kind);
237+
238+
abstract predicate sinkModel(string type, string path, string kind);
239+
240+
abstract predicate summaryModel(string type, string path, string input, string output, string kind);
241+
242+
abstract predicate typeModel(string type1, string type2, string path);
243+
244+
abstract predicate typeVariableModel(string name, string path);
245+
}
246+
247+
private class DeprecationAdapterImpl extends DeprecationAdapter {
248+
deprecated override predicate sourceModel(string type, string path, string kind) {
249+
exists(string row |
250+
sourceModel(row) and
251+
row.splitAt(";", 0) = type and
252+
row.splitAt(";", 1) = path and
253+
row.splitAt(";", 2) = kind
254+
)
255+
}
256+
257+
deprecated override predicate sinkModel(string type, string path, string kind) {
258+
exists(string row |
259+
sinkModel(row) and
260+
row.splitAt(";", 0) = type and
261+
row.splitAt(";", 1) = path and
262+
row.splitAt(";", 2) = kind
263+
)
264+
}
265+
266+
deprecated override predicate summaryModel(
267+
string type, string path, string input, string output, string kind
268+
) {
269+
exists(string row |
270+
summaryModel(row) and
271+
row.splitAt(";", 0) = type and
272+
row.splitAt(";", 1) = path and
273+
row.splitAt(";", 2) = input and
274+
row.splitAt(";", 3) = output and
275+
row.splitAt(";", 4) = kind
276+
)
277+
}
226278

227-
private predicate typeModel(string row) { any(TypeModelCsv s).row(inversePad(row)) }
279+
deprecated override predicate typeModel(string type1, string type2, string path) {
280+
exists(string row |
281+
typeModel(row) and
282+
row.splitAt(";", 0) = type1 and
283+
row.splitAt(";", 1) = type2 and
284+
row.splitAt(";", 2) = path
285+
)
286+
}
228287

229-
private predicate typeVariableModel(string row) { any(TypeVariableModelCsv s).row(inversePad(row)) }
288+
deprecated override predicate typeVariableModel(string name, string path) {
289+
exists(string row |
290+
typeVariableModel(row) and
291+
row.splitAt(";", 0) = name and
292+
row.splitAt(";", 1) = path
293+
)
294+
}
295+
}
230296

231297
/** Holds if a source model exists for the given parameters. */
232298
predicate sourceModel(string type, string path, string kind, string model) {
233-
exists(string row |
234-
sourceModel(row) and
235-
row.splitAt(";", 0) = type and
236-
row.splitAt(";", 1) = path and
237-
row.splitAt(";", 2) = kind and
238-
model = "SourceModelCsv"
239-
)
299+
any(DeprecationAdapter a).sourceModel(type, path, kind) and
300+
model = "SourceModelCsv"
240301
or
241302
exists(QlBuiltins::ExtensionId madId |
242303
Extensions::sourceModel(type, path, kind, madId) and
@@ -246,13 +307,8 @@ predicate sourceModel(string type, string path, string kind, string model) {
246307

247308
/** Holds if a sink model exists for the given parameters. */
248309
private predicate sinkModel(string type, string path, string kind, string model) {
249-
exists(string row |
250-
sinkModel(row) and
251-
row.splitAt(";", 0) = type and
252-
row.splitAt(";", 1) = path and
253-
row.splitAt(";", 2) = kind and
254-
model = "SinkModelCsv"
255-
)
310+
any(DeprecationAdapter a).sinkModel(type, path, kind) and
311+
model = "SinkModelCsv"
256312
or
257313
exists(QlBuiltins::ExtensionId madId |
258314
Extensions::sinkModel(type, path, kind, madId) and
@@ -264,15 +320,8 @@ private predicate sinkModel(string type, string path, string kind, string model)
264320
private predicate summaryModel(
265321
string type, string path, string input, string output, string kind, string model
266322
) {
267-
exists(string row |
268-
summaryModel(row) and
269-
row.splitAt(";", 0) = type and
270-
row.splitAt(";", 1) = path and
271-
row.splitAt(";", 2) = input and
272-
row.splitAt(";", 3) = output and
273-
row.splitAt(";", 4) = kind and
274-
model = "SummaryModelCsv"
275-
)
323+
any(DeprecationAdapter a).summaryModel(type, path, input, output, kind) and
324+
model = "SummaryModelCsv"
276325
or
277326
exists(QlBuiltins::ExtensionId madId |
278327
Extensions::summaryModel(type, path, input, output, kind, madId) and
@@ -282,29 +331,20 @@ private predicate summaryModel(
282331

283332
/** Holds if a type model exists for the given parameters. */
284333
private predicate typeModel(string type1, string type2, string path) {
285-
exists(string row |
286-
typeModel(row) and
287-
row.splitAt(";", 0) = type1 and
288-
row.splitAt(";", 1) = type2 and
289-
row.splitAt(";", 2) = path
290-
)
334+
any(DeprecationAdapter a).typeModel(type1, type2, path)
291335
or
292336
Extensions::typeModel(type1, type2, path)
293337
}
294338

295339
/** Holds if a type variable model exists for the given parameters. */
296340
private predicate typeVariableModel(string name, string path) {
297-
exists(string row |
298-
typeVariableModel(row) and
299-
row.splitAt(";", 0) = name and
300-
row.splitAt(";", 1) = path
301-
)
341+
any(DeprecationAdapter a).typeVariableModel(name, path)
302342
or
303343
Extensions::typeVariableModel(name, path)
304344
}
305345

306346
/**
307-
* Holds if CSV rows involving `type` might be relevant for the analysis of this database.
347+
* Holds if rows involving `type` might be relevant for the analysis of this database.
308348
*/
309349
predicate isRelevantType(string type) {
310350
(
@@ -327,7 +367,7 @@ predicate isRelevantType(string type) {
327367
}
328368

329369
/**
330-
* Holds if `type,path` is used in some CSV row.
370+
* Holds if `type,path` is used in some row.
331371
*/
332372
pragma[nomagic]
333373
predicate isRelevantFullPath(string type, string path) {
@@ -340,7 +380,7 @@ predicate isRelevantFullPath(string type, string path) {
340380
)
341381
}
342382

343-
/** A string from a CSV row that should be parsed as an access path. */
383+
/** A string from a row that should be parsed as an access path. */
344384
private predicate accessPathRange(string s) {
345385
isRelevantFullPath(_, s)
346386
or
@@ -632,7 +672,7 @@ module ModelOutput {
632672
cached
633673
private module Cached {
634674
/**
635-
* Holds if a CSV source model contributed `source` with the given `kind`.
675+
* Holds if a source model contributed `source` with the given `kind`.
636676
*/
637677
cached
638678
API::Node getASourceNode(string kind, string model) {
@@ -643,7 +683,7 @@ module ModelOutput {
643683
}
644684

645685
/**
646-
* Holds if a CSV sink model contributed `sink` with the given `kind`.
686+
* Holds if a sink model contributed `sink` with the given `kind`.
647687
*/
648688
cached
649689
API::Node getASinkNode(string kind, string model) {
@@ -654,7 +694,7 @@ module ModelOutput {
654694
}
655695

656696
/**
657-
* Holds if a relevant CSV summary exists for these parameters.
697+
* Holds if a relevant summary exists for these parameters.
658698
*/
659699
cached
660700
predicate relevantSummaryModel(
@@ -684,7 +724,7 @@ module ModelOutput {
684724

685725
/**
686726
* Holds if `node` is seen as an instance of `type` due to a type definition
687-
* contributed by a CSV model.
727+
* contributed by a model.
688728
*/
689729
cached
690730
API::Node getATypeNode(string type) { result = getNodeFromType(type) }
@@ -718,25 +758,6 @@ module ModelOutput {
718758
* Gets an error message relating to an invalid CSV row in a model.
719759
*/
720760
string getAWarning() {
721-
// Check number of columns
722-
exists(string row, string kind, int expectedArity, int actualArity |
723-
any(SourceModelCsv csv).row(row) and kind = "source" and expectedArity = 3
724-
or
725-
any(SinkModelCsv csv).row(row) and kind = "sink" and expectedArity = 3
726-
or
727-
any(SummaryModelCsv csv).row(row) and kind = "summary" and expectedArity = 5
728-
or
729-
any(TypeModelCsv csv).row(row) and kind = "type" and expectedArity = 3
730-
or
731-
any(TypeVariableModelCsv csv).row(row) and kind = "type-variable" and expectedArity = 2
732-
|
733-
actualArity = count(row.indexOf(";")) + 1 and
734-
actualArity != expectedArity and
735-
result =
736-
"CSV " + kind + " row should have " + expectedArity + " columns but has " + actualArity +
737-
": " + row
738-
)
739-
or
740761
// Check names and arguments of access path tokens
741762
exists(AccessPath path, AccessPathToken token |
742763
(isRelevantFullPath(_, path) or typeVariableModel(_, path)) and

0 commit comments

Comments
 (0)