@@ -98,6 +98,8 @@ import getComponentNameFromType from 'shared/getComponentNameFromType';
9898
9999import { getOwnerStackByComponentInfoInDev } from 'shared/ReactComponentInfoStack' ;
100100
101+ import hasOwnProperty from 'shared/hasOwnProperty' ;
102+
101103import { injectInternals } from './ReactFlightClientDevToolsHook' ;
102104
103105import { OMITTED_PROP_ERROR } from 'shared/ReactFlightPropertyAccess' ;
@@ -163,6 +165,8 @@ const INITIALIZED = 'fulfilled';
163165const ERRORED = 'rejected' ;
164166const HALTED = 'halted' ; // DEV-only. Means it never resolves even if connection closes.
165167
168+ const __PROTO__ = '__proto__' ;
169+
166170type PendingChunk < T > = {
167171 status : 'pending' ,
168172 value : null | Array < InitializationReference | ( T => mixed ) > ,
@@ -1496,7 +1500,16 @@ function fulfillReference(
14961500 }
14971501 }
14981502 }
1499- value = value [ path [ i ] ] ;
1503+ const name = path [ i ] ;
1504+ if (
1505+ typeof value === 'object ' &&
1506+ value !== null &&
1507+ hasOwnProperty . call ( value , name )
1508+ ) {
1509+ value = value [ name ] ;
1510+ } else {
1511+ throw new Error ( 'Invalid reference.' ) ;
1512+ }
15001513 }
15011514
15021515 while (
@@ -1532,7 +1545,9 @@ function fulfillReference(
15321545 }
15331546
15341547 const mappedValue = map(response, value, parentObject, key);
1535- parentObject [ key ] = mappedValue ;
1548+ if (key !== __PROTO__) {
1549+ parentObject [ key ] = mappedValue ;
1550+ }
15361551
15371552 // If this is the root object for a model reference, where `handler.value`
15381553 // is a stale `null`, the resolved value can be used directly.
@@ -1799,7 +1814,9 @@ function loadServerReference<A: Iterable<any>, T>(
17991814 response . _encodeFormAction ,
18001815 ) ;
18011816
1802- parentObject [ key ] = resolvedValue ;
1817+ if ( key !== __PROTO__ ) {
1818+ parentObject [ key ] = resolvedValue ;
1819+ }
18031820
18041821 // If this is the root object for a model reference, where `handler.value`
18051822 // is a stale `null`, the resolved value can be used directly.
@@ -2177,29 +2194,31 @@ function defineLazyGetter<T>(
21772194): any {
21782195 // We don't immediately initialize it even if it's resolved.
21792196 // Instead, we wait for the getter to get accessed.
2180- Object . defineProperty ( parentObject , key , {
2181- get : function ( ) {
2182- if ( chunk . status === RESOLVED_MODEL ) {
2183- // If it was now resolved, then we initialize it. This may then discover
2184- // a new set of lazy references that are then asked for eagerly in case
2185- // we get that deep.
2186- initializeModelChunk ( chunk ) ;
2187- }
2188- switch ( chunk . status ) {
2189- case INITIALIZED : {
2190- return chunk . value ;
2197+ if ( key !== __PROTO__ ) {
2198+ Object . defineProperty ( parentObject , key , {
2199+ get : function ( ) {
2200+ if ( chunk . status === RESOLVED_MODEL ) {
2201+ // If it was now resolved, then we initialize it. This may then discover
2202+ // a new set of lazy references that are then asked for eagerly in case
2203+ // we get that deep.
2204+ initializeModelChunk ( chunk ) ;
21912205 }
2192- case ERRORED :
2193- throw chunk . reason ;
2194- }
2195- // Otherwise, we didn't have enough time to load the object before it was
2196- // accessed or the connection closed. So we just log that it was omitted.
2197- // TODO: We should ideally throw here to indicate a difference.
2198- return OMITTED_PROP_ERROR ;
2199- } ,
2200- enumerable : true ,
2201- configurable : false ,
2202- } ) ;
2206+ switch ( chunk . status ) {
2207+ case INITIALIZED : {
2208+ return chunk . value ;
2209+ }
2210+ case ERRORED :
2211+ throw chunk . reason ;
2212+ }
2213+ // Otherwise, we didn't have enough time to load the object before it was
2214+ // accessed or the connection closed. So we just log that it was omitted.
2215+ // TODO: We should ideally throw here to indicate a difference.
2216+ return OMITTED_PROP_ERROR ;
2217+ } ,
2218+ enumerable : true ,
2219+ configurable : false ,
2220+ } ) ;
2221+ }
22032222 return null;
22042223}
22052224
@@ -2510,14 +2529,16 @@ function parseModelString(
25102529 // In DEV mode we encode omitted objects in logs as a getter that throws
25112530 // so that when you try to access it on the client, you know why that
25122531 // happened.
2513- Object . defineProperty ( parentObject , key, {
2514- get : function ( ) {
2515- // TODO: We should ideally throw here to indicate a difference.
2516- return OMITTED_PROP_ERROR ;
2517- } ,
2518- enumerable : true ,
2519- configurable : false ,
2520- } ) ;
2532+ if ( key !== __PROTO__ ) {
2533+ Object . defineProperty ( parentObject , key, {
2534+ get : function ( ) {
2535+ // TODO: We should ideally throw here to indicate a difference.
2536+ return OMITTED_PROP_ERROR ;
2537+ } ,
2538+ enumerable : true ,
2539+ configurable : false ,
2540+ } ) ;
2541+ }
25212542 return null;
25222543 }
25232544 // Fallthrough
@@ -5143,6 +5164,9 @@ function parseModel<T>(response: Response, json: UninitializedModel): T {
51435164function createFromJSONCallback ( response : Response ) {
51445165 // $FlowFixMe[missing-this-annot]
51455166 return function ( key : string , value : JSONValue ) {
5167+ if ( key === __PROTO__ ) {
5168+ return undefined ;
5169+ }
51465170 if ( typeof value === 'string ') {
51475171 // We can't use .bind here because we need the "this" value.
51485172 return parseModelString ( response , this , key , value ) ;
0 commit comments