Skip to content

Commit cc1a28a

Browse files
committed
JS: Add parameters of server functions as remote flow sources
1 parent d9f4e4a commit cc1a28a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

javascript/ql/lib/semmle/javascript/frameworks/React.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,3 +875,22 @@ private class ReactPropAsViewComponentInput extends ViewComponentInput {
875875

876876
override string getSourceType() { result = "React props" }
877877
}
878+
879+
private predicate isServerFunction(DataFlow::FunctionNode func) {
880+
exists(Directive::UseServerDirective useServer |
881+
useServer.getContainer() = func.getFunction()
882+
or
883+
useServer.getContainer().(Module).getAnExportedValue(_).getAFunctionValue() = func
884+
)
885+
}
886+
887+
private class ServerFunctionRemoteFlowSource extends RemoteFlowSource {
888+
ServerFunctionRemoteFlowSource() {
889+
exists(DataFlow::FunctionNode func |
890+
isServerFunction(func) and
891+
this = func.getAParameter()
892+
)
893+
}
894+
895+
override string getSourceType() { result = "React server function parameter" }
896+
}

javascript/ql/test/library-tests/frameworks/ReactJS/tests.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,7 @@ threatModelSource
305305
| statePropertyWrites.js:38:24:38:33 | this.props | view-component-input |
306306
| thisAccesses.js:31:12:31:16 | props | view-component-input |
307307
| thisAccesses.js:48:18:48:18 | y | view-component-input |
308+
| use-server1.js:2:5:2:5 | x | remote |
309+
| use-server1.js:3:5:3:5 | y | remote |
310+
| use-server2.js:4:5:4:5 | x | remote |
311+
| use-server2.js:5:5:5:5 | y | remote |

javascript/ql/test/library-tests/frameworks/ReactJS/use-server1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
async function getData(
2-
x, // $ MISSING: threatModelSource=remote
3-
y) { // $ MISSING: threatModelSource=remote
2+
x, // $ threatModelSource=remote
3+
y) { // $ threatModelSource=remote
44
"use server";
55
}
66

javascript/ql/test/library-tests/frameworks/ReactJS/use-server2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use server";
22

33
export async function getData(
4-
x, // $ MISSING: threatModelSource=remote
5-
y) { // $ MISSING: threatModelSource=remote
4+
x, // $ threatModelSource=remote
5+
y) { // $ threatModelSource=remote
66
}
77

88
async function getData2(

0 commit comments

Comments
 (0)