@@ -13,6 +13,7 @@ private import sharedlib.FlowSummaryImpl as FlowSummaryImpl
13
13
private import semmle.javascript.dataflow.internal.FlowSummaryPrivate as FlowSummaryPrivate
14
14
private import semmle.javascript.dataflow.FlowSummary as FlowSummary
15
15
private import semmle.javascript.dataflow.internal.BarrierGuards
16
+ private import codeql.util.Boolean
16
17
17
18
class DataFlowSecondLevelScope = Unit ;
18
19
@@ -363,6 +364,8 @@ predicate postUpdatePair(Node pre, Node post) {
363
364
pre .( FlowSummaryNode ) .getSummaryNode ( ) )
364
365
or
365
366
VariableCaptureOutput:: capturePostUpdateNode ( getClosureNode ( post ) , getClosureNode ( pre ) )
367
+ or
368
+ any ( AdditionalFlowInternal f ) .postUpdate ( pre , post )
366
369
}
367
370
368
371
class CastNode extends DataFlow:: Node {
@@ -381,10 +384,16 @@ newtype TDataFlowCallable =
381
384
not f instanceof ArrowFunctionExpr and
382
385
// We also don't need harnesses for externs
383
386
not f .getTopLevel ( ) .isExterns ( )
387
+ } or
388
+ /**
389
+ * A callable entity. This is a wrapper around either a `StmtContainer`, `LibraryCallable`, or `File`.
390
+ */
391
+ MkGenericSynthesizedCallable ( AstNode node , string tag ) {
392
+ any ( AdditionalFlowInternal f ) .needsSynthesizedCallable ( node , tag )
384
393
}
385
394
386
395
/**
387
- * A callable entity. This is a wrapper around either a `StmtContainer`, `LibraryCallable`, or `File`.
396
+ * A callable entity.
388
397
*/
389
398
class DataFlowCallable extends TDataFlowCallable {
390
399
/** Gets a string representation of this callable. */
@@ -395,7 +404,7 @@ class DataFlowCallable extends TDataFlowCallable {
395
404
or
396
405
result = this .asFileCallable ( ) .toString ( )
397
406
or
398
- result = this .asClassHarness ( ) . toString ( )
407
+ this .isGenericSynthesizedCallable ( _ , result )
399
408
}
400
409
401
410
/** Gets the location of this callable, if it is present in the source code. */
@@ -404,7 +413,10 @@ class DataFlowCallable extends TDataFlowCallable {
404
413
or
405
414
result = this .asFileCallable ( ) .getLocation ( )
406
415
or
407
- result = this .asClassHarness ( ) .getLocation ( )
416
+ exists ( AstNode node |
417
+ this .isGenericSynthesizedCallable ( node , _) and
418
+ result = node .getLocation ( )
419
+ )
408
420
}
409
421
410
422
/** Gets the corresponding `StmtContainer` if this is a source callable. */
@@ -414,7 +426,9 @@ class DataFlowCallable extends TDataFlowCallable {
414
426
File asFileCallable ( ) { this = MkFileCallable ( result ) }
415
427
416
428
/** Gets the class constructor for which this is a class harness. */
417
- Function asClassHarness ( ) { this = MkClassHarnessCallable ( result ) }
429
+ predicate isGenericSynthesizedCallable ( AstNode node , string tag ) {
430
+ this = MkGenericSynthesizedCallable ( node , tag )
431
+ }
418
432
419
433
/** Gets the corresponding `StmtContainer` if this is a source callable. */
420
434
pragma [ nomagic]
@@ -544,6 +558,8 @@ private predicate isArgumentNodeImpl(Node n, DataFlowCall call, ArgumentPosition
544
558
n = TDynamicArgumentArrayNode ( invoke ) and
545
559
pos .isDynamicArgumentArray ( )
546
560
)
561
+ or
562
+ any ( AdditionalFlowInternal f ) .argument ( call , pos , n )
547
563
}
548
564
549
565
predicate isArgumentNode ( ArgumentNode n , DataFlowCall call , ArgumentPosition pos ) {
@@ -791,7 +807,7 @@ ContentApprox getContentApprox(Content c) {
791
807
}
792
808
793
809
cached
794
- private newtype TDataFlowCall =
810
+ newtype TDataFlowCall =
795
811
MkOrdinaryCall ( DataFlow:: InvokeNode node ) or
796
812
MkPartialCall ( DataFlow:: PartialInvokeNode node , DataFlow:: Node callback ) {
797
813
callback = node .getACallbackNode ( )
@@ -812,6 +828,9 @@ private newtype TDataFlowCall =
812
828
FlowSummaryImpl:: Public:: SummarizedCallable c , FlowSummaryImpl:: Private:: SummaryNode receiver
813
829
) {
814
830
FlowSummaryImpl:: Private:: summaryCallbackRange ( c , receiver )
831
+ } or
832
+ MkGenericSynthesizedCall ( AstNode node , string tag , DataFlowCallable container ) {
833
+ any ( AdditionalFlowInternal f ) .needsSynthesizedCall ( node , tag , container )
815
834
}
816
835
817
836
private module TotalOrdering {
@@ -877,6 +896,10 @@ class DataFlowCall extends TDataFlowCall {
877
896
this = MkSummaryCall ( enclosingCallable , receiver )
878
897
}
879
898
899
+ predicate isGenericSynthesizedCall ( AstNode node , string tag , DataFlowCallable container ) {
900
+ this = MkGenericSynthesizedCall ( node , tag , container )
901
+ }
902
+
880
903
Location getLocation ( ) { none ( ) } // Overridden in subclass
881
904
882
905
int totalorder ( ) {
@@ -995,6 +1018,20 @@ private class ImpliedLambdaCall extends DataFlowCall, MkImpliedLambdaCall {
995
1018
}
996
1019
}
997
1020
1021
+ class GenericSynthesizedCall extends DataFlowCall , MkGenericSynthesizedCall {
1022
+ private AstNode node ;
1023
+ private string tag ;
1024
+ private DataFlowCallable container ;
1025
+
1026
+ GenericSynthesizedCall ( ) { this = MkGenericSynthesizedCall ( node , tag , container ) }
1027
+
1028
+ override string toString ( ) { result = tag }
1029
+
1030
+ override Location getLocation ( ) { result = node .getLocation ( ) }
1031
+
1032
+ override DataFlowCallable getEnclosingCallable ( ) { result = container }
1033
+ }
1034
+
998
1035
private int getMaxArity ( ) {
999
1036
// TODO: account for flow summaries
1000
1037
result =
@@ -1092,6 +1129,8 @@ DataFlowCallable viableCallable(DataFlowCall node) {
1092
1129
)
1093
1130
or
1094
1131
result .asSourceCallableNotExterns ( ) = node .asImpliedLambdaCall ( )
1132
+ or
1133
+ any ( AdditionalFlowInternal f ) .viableCallable ( node , result )
1095
1134
}
1096
1135
1097
1136
private DataFlowCall getACallOnThis ( DataFlow:: ClassNode cls ) {
0 commit comments