Skip to content

Commit 11132bf

Browse files
committed
JS: Sync.
1 parent ba72643 commit 11132bf

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

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

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -229,41 +229,55 @@ private predicate typeModel(string row) { any(TypeModelCsv s).row(inversePad(row
229229
private predicate typeVariableModel(string row) { any(TypeVariableModelCsv s).row(inversePad(row)) }
230230

231231
/** Holds if a source model exists for the given parameters. */
232-
predicate sourceModel(string type, string path, string kind) {
232+
predicate sourceModel(string type, string path, string kind, string model) {
233233
exists(string row |
234234
sourceModel(row) and
235235
row.splitAt(";", 0) = type and
236236
row.splitAt(";", 1) = path and
237-
row.splitAt(";", 2) = kind
237+
row.splitAt(";", 2) = kind and
238+
model = "SourceModelCsv"
238239
)
239240
or
240-
Extensions::sourceModel(type, path, kind)
241+
exists(QlBuiltins::ExtensionId madId |
242+
Extensions::sourceModel(type, path, kind, madId) and
243+
model = "MaD:" + madId.toString()
244+
)
241245
}
242246

243247
/** Holds if a sink model exists for the given parameters. */
244-
private predicate sinkModel(string type, string path, string kind) {
248+
private predicate sinkModel(string type, string path, string kind, string model) {
245249
exists(string row |
246250
sinkModel(row) and
247251
row.splitAt(";", 0) = type and
248252
row.splitAt(";", 1) = path and
249-
row.splitAt(";", 2) = kind
253+
row.splitAt(";", 2) = kind and
254+
model = "SinkModelCsv"
250255
)
251256
or
252-
Extensions::sinkModel(type, path, kind)
257+
exists(QlBuiltins::ExtensionId madId |
258+
Extensions::sinkModel(type, path, kind, madId) and
259+
model = "MaD:" + madId.toString()
260+
)
253261
}
254262

255263
/** Holds if a summary model `row` exists for the given parameters. */
256-
private predicate summaryModel(string type, string path, string input, string output, string kind) {
264+
private predicate summaryModel(
265+
string type, string path, string input, string output, string kind, string model
266+
) {
257267
exists(string row |
258268
summaryModel(row) and
259269
row.splitAt(";", 0) = type and
260270
row.splitAt(";", 1) = path and
261271
row.splitAt(";", 2) = input and
262272
row.splitAt(";", 3) = output and
263-
row.splitAt(";", 4) = kind
273+
row.splitAt(";", 4) = kind and
274+
model = "SummaryModelCsv"
264275
)
265276
or
266-
Extensions::summaryModel(type, path, input, output, kind)
277+
exists(QlBuiltins::ExtensionId madId |
278+
Extensions::summaryModel(type, path, input, output, kind, madId) and
279+
model = "MaD:" + madId.toString()
280+
)
267281
}
268282

269283
/** Holds if a type model exists for the given parameters. */
@@ -294,9 +308,9 @@ private predicate typeVariableModel(string name, string path) {
294308
*/
295309
predicate isRelevantType(string type) {
296310
(
297-
sourceModel(type, _, _) or
298-
sinkModel(type, _, _) or
299-
summaryModel(type, _, _, _, _) or
311+
sourceModel(type, _, _, _) or
312+
sinkModel(type, _, _, _) or
313+
summaryModel(type, _, _, _, _, _) or
300314
typeModel(_, type, _)
301315
) and
302316
(
@@ -319,9 +333,9 @@ pragma[nomagic]
319333
predicate isRelevantFullPath(string type, string path) {
320334
isRelevantType(type) and
321335
(
322-
sourceModel(type, path, _) or
323-
sinkModel(type, path, _) or
324-
summaryModel(type, path, _, _, _) or
336+
sourceModel(type, path, _, _) or
337+
sinkModel(type, path, _, _) or
338+
summaryModel(type, path, _, _, _, _) or
325339
typeModel(_, type, path)
326340
)
327341
}
@@ -331,8 +345,8 @@ private predicate accessPathRange(string s) {
331345
isRelevantFullPath(_, s)
332346
or
333347
exists(string type | isRelevantType(type) |
334-
summaryModel(type, _, s, _, _) or
335-
summaryModel(type, _, _, s, _)
348+
summaryModel(type, _, s, _, _, _) or
349+
summaryModel(type, _, _, s, _, _)
336350
)
337351
or
338352
typeVariableModel(_, s)
@@ -543,7 +557,7 @@ private API::Node getNodeFromPath(string type, AccessPath path) {
543557

544558
pragma[nomagic]
545559
private predicate typeStepModel(string type, AccessPath basePath, AccessPath output) {
546-
summaryModel(type, basePath, "", output, "type")
560+
summaryModel(type, basePath, "", output, "type", _)
547561
}
548562

549563
pragma[nomagic]
@@ -621,9 +635,9 @@ module ModelOutput {
621635
* Holds if a CSV source model contributed `source` with the given `kind`.
622636
*/
623637
cached
624-
API::Node getASourceNode(string kind) {
638+
API::Node getASourceNode(string kind, string model) {
625639
exists(string type, string path |
626-
sourceModel(type, path, kind) and
640+
sourceModel(type, path, kind, model) and
627641
result = getNodeFromPath(type, path)
628642
)
629643
}
@@ -632,9 +646,9 @@ module ModelOutput {
632646
* Holds if a CSV sink model contributed `sink` with the given `kind`.
633647
*/
634648
cached
635-
API::Node getASinkNode(string kind) {
649+
API::Node getASinkNode(string kind, string model) {
636650
exists(string type, string path |
637-
sinkModel(type, path, kind) and
651+
sinkModel(type, path, kind, model) and
638652
result = getNodeFromPath(type, path)
639653
)
640654
}
@@ -644,18 +658,18 @@ module ModelOutput {
644658
*/
645659
cached
646660
predicate relevantSummaryModel(
647-
string type, string path, string input, string output, string kind
661+
string type, string path, string input, string output, string kind, string model
648662
) {
649663
isRelevantType(type) and
650-
summaryModel(type, path, input, output, kind)
664+
summaryModel(type, path, input, output, kind, model)
651665
}
652666

653667
/**
654668
* Holds if a `baseNode` is an invocation identified by the `type,path` part of a summary row.
655669
*/
656670
cached
657671
predicate resolvedSummaryBase(string type, string path, Specific::InvokeNode baseNode) {
658-
summaryModel(type, path, _, _, _) and
672+
summaryModel(type, path, _, _, _, _) and
659673
baseNode = getInvocationFromPath(type, path)
660674
}
661675

@@ -664,7 +678,7 @@ module ModelOutput {
664678
*/
665679
cached
666680
predicate resolvedSummaryRefBase(string type, string path, API::Node baseNode) {
667-
summaryModel(type, path, _, _, _) and
681+
summaryModel(type, path, _, _, _, _) and
668682
baseNode = getNodeFromPath(type, path)
669683
}
670684

@@ -680,12 +694,22 @@ module ModelOutput {
680694
import Specific::ModelOutputSpecific
681695
private import codeql.mad.ModelValidation as SharedModelVal
682696

697+
/**
698+
* Holds if a CSV source model contributed `source` with the given `kind`.
699+
*/
700+
API::Node getASourceNode(string kind) { result = getASourceNode(kind, _) }
701+
702+
/**
703+
* Holds if a CSV sink model contributed `sink` with the given `kind`.
704+
*/
705+
API::Node getASinkNode(string kind) { result = getASinkNode(kind, _) }
706+
683707
private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
684-
predicate summaryKind(string kind) { summaryModel(_, _, _, _, kind) }
708+
predicate summaryKind(string kind) { summaryModel(_, _, _, _, kind, _) }
685709

686-
predicate sinkKind(string kind) { sinkModel(_, _, kind) }
710+
predicate sinkKind(string kind) { sinkModel(_, _, kind, _) }
687711

688-
predicate sourceKind(string kind) { sourceModel(_, _, kind) }
712+
predicate sourceKind(string kind) { sourceModel(_, _, kind, _) }
689713
}
690714

691715
private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
*
99
* The kind `remote` represents a general remote flow source.
1010
*/
11-
extensible predicate sourceModel(string type, string path, string kind);
11+
extensible predicate sourceModel(
12+
string type, string path, string kind, QlBuiltins::ExtensionId madId
13+
);
1214

1315
/**
1416
* Holds if the value at `(type, path)` should be seen as a sink
1517
* of the given `kind`.
1618
*/
17-
extensible predicate sinkModel(string type, string path, string kind);
19+
extensible predicate sinkModel(string type, string path, string kind, QlBuiltins::ExtensionId madId);
1820

1921
/**
2022
* Holds if in calls to `(type, path)`, the value referred to by `input`
@@ -23,7 +25,9 @@ extensible predicate sinkModel(string type, string path, string kind);
2325
* `kind` should be either `value` or `taint`, for value-preserving or taint-preserving steps,
2426
* respectively.
2527
*/
26-
extensible predicate summaryModel(string type, string path, string input, string output, string kind);
28+
extensible predicate summaryModel(
29+
string type, string path, string input, string output, string kind, QlBuiltins::ExtensionId madId
30+
);
2731

2832
/**
2933
* Holds if calls to `(type, path)` should be considered neutral. The meaning of this depends on the `kind`.

0 commit comments

Comments
 (0)