Skip to content

Commit 3016ff8

Browse files
authored
[Flight] Never parse "then" functions (facebook#35289)
AFAIK this is not needed to prevent any exploit but we don't really need this. We allow functions on pretty much any other object anyway but never on the "then" property since those would be serialized as Promises by the client anyway.
1 parent f99241b commit 3016ff8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/react-server/src/ReactFlightReplyServer.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ function loadServerReference<A: Iterable<any>, T>(
437437
if (typeof id !== 'string') {
438438
return (null: any);
439439
}
440+
if (key === 'then') {
441+
// This should never happen because we always serialize objects with then-functions
442+
// as "thenable" which reduces to ReactPromise with no other fields.
443+
return (null: any);
444+
}
440445
const serverReference: ServerReference<T> =
441446
resolveServerReference<$FlowFixMe>(response._bundlerConfig, id);
442447
// We expect most servers to not really need this because you'd just have all
@@ -976,7 +981,17 @@ function extractIterator(response: Response, model: Array<any>): Iterator<any> {
976981
return model[Symbol.iterator]();
977982
}
978983

979-
function createModel(response: Response, model: any): any {
984+
function createModel(
985+
response: Response,
986+
model: any,
987+
parentObject: Object,
988+
key: string,
989+
): any {
990+
if (key === 'then' && typeof model === 'function') {
991+
// This should never happen because we always serialize objects with then-functions
992+
// as "thenable" which reduces to ReactPromise with no other fields.
993+
return null;
994+
}
980995
return model;
981996
}
982997

0 commit comments

Comments
 (0)