add support for getInitialProps in Next.js

This commit is contained in:
Erik Krogh Kristensen
2021-02-16 10:22:21 +01:00
parent d63fcaf7f1
commit af262a035d
3 changed files with 21 additions and 4 deletions

View File

@@ -67,12 +67,23 @@ private module NextJS {
NextJSStaticPropsStep() {
pageModule = getAPagesModule() and
this = pageModule.getAnExportedValue("getStaticProps").getAFunctionValue()
this = pageModule.getAnExportedValue("default").getAFunctionValue()
}
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
pred = this.getAReturn().getALocalSource().getAPropertyWrite("props").getRhs() and
succ = pageModule.getAnExportedValue("default").getAFunctionValue().getParameter(0)
(
pred =
pageModule
.getAnExportedValue("getStaticProps")
.getAFunctionValue()
.getAReturn()
.getALocalSource()
.getAPropertyWrite("props")
.getRhs()
or
pred = this.getAPropertyWrite("getInitialProps").getRhs().getAFunctionValue().getAReturn()
) and
succ = this.getParameter(0)
}
}
}

View File

@@ -15,7 +15,12 @@ export async function getStaticProps({ params }) {
}
}
export default function Post({ taint }) {
export default function Post({ taint, stars }) {
sink(taint);
sink(stars);
return <span />;
}
Post.getInitialProps = async (ctx) => {
return { stars: source(2) }
}

View File

@@ -2,3 +2,4 @@ remoteFlow
| pages/[my-fallback-id].jsx:9:40:9:45 | params |
dataFlow
| pages/[my-fallback-id].jsx:13:20:13:27 | source() | pages/[my-fallback-id].jsx:19:10:19:14 | taint |
| pages/[my-fallback-id].jsx:25:21:25:29 | source(2) | pages/[my-fallback-id].jsx:20:10:20:14 | stars |