@@ -23,13 +23,18 @@ private module NextJS {
23
23
result = getAPagesFolder ( ) .getAFolder ( )
24
24
}
25
25
26
+ /**
27
+ * Gets a module corrosponding to a `Next.js` page.
28
+ */
29
+ Module getAPagesModule ( ) { result .getFile ( ) .getParentContainer ( ) = getAPagesFolder ( ) }
30
+
26
31
/**
27
32
* Gets a module inside a "pages" folder where `fallback` from `getStaticPaths` is not set to false.
28
33
* In such a module the `getStaticProps` method can be called with user-defined parameters.
29
34
* If `fallback` is set to false, then only values defined by `getStaticPaths` are allowed.
30
35
*/
31
36
Module getAModuleWithFallbackPaths ( ) {
32
- result . getFile ( ) . getParentContainer ( ) = getAPagesFolder ( ) and
37
+ result = getAPagesModule ( ) and
33
38
exists ( DataFlow:: FunctionNode staticPaths , Expr fallback |
34
39
staticPaths = result .getAnExportedValue ( "getStaticPaths" ) .getAFunctionValue ( ) and
35
40
fallback =
@@ -53,4 +58,21 @@ private module NextJS {
53
58
54
59
override string getSourceType ( ) { result = "Next request parameter" }
55
60
}
61
+
62
+ /**
63
+ * A step modelling the flow from the server-computed `getStaticProps` to the server/client rendering of the page.
64
+ */
65
+ class NextJSStaticPropsStep extends DataFlow:: AdditionalFlowStep , DataFlow:: FunctionNode {
66
+ Module pageModule ;
67
+
68
+ NextJSStaticPropsStep ( ) {
69
+ pageModule = getAPagesModule ( ) and
70
+ this = pageModule .getAnExportedValue ( "getStaticProps" ) .getAFunctionValue ( )
71
+ }
72
+
73
+ override predicate step ( DataFlow:: Node pred , DataFlow:: Node succ ) {
74
+ pred = this .getAReturn ( ) .getALocalSource ( ) .getAPropertyWrite ( "props" ) .getRhs ( ) and
75
+ succ = pageModule .getAnExportedValue ( "default" ) .getAFunctionValue ( ) .getParameter ( 0 )
76
+ }
77
+ }
56
78
}
0 commit comments