File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -289,9 +289,16 @@ const rscBridgeRuntimePlugin = (): ModuleFederationRuntimePlugin => {
289289 '[modern-js-v3:rsc-bridge] Module Federation runtime instance is unavailable while loading the RSC bridge' ,
290290 ) ;
291291 }
292- const bridgePromise = Promise . resolve (
293- runtimeInstance . loadRemote ( `${ alias } /${ RSC_BRIDGE_EXPOSE } ` ) ,
294- )
292+ let resolveBridge ! : ( bridge : BridgeModule ) => void ;
293+ let rejectBridge ! : ( error : unknown ) => void ;
294+ const bridgePromise = new Promise < BridgeModule > ( ( resolve , reject ) => {
295+ resolveBridge = resolve ;
296+ rejectBridge = reject ;
297+ } ) ;
298+ bridgePromises [ alias ] = bridgePromise ;
299+
300+ void Promise . resolve ( )
301+ . then ( ( ) => runtimeInstance . loadRemote ( `${ alias } /${ RSC_BRIDGE_EXPOSE } ` ) )
295302 . then ( ( bridge : BridgeModule ) => {
296303 if (
297304 ! bridge ||
@@ -302,14 +309,14 @@ const rscBridgeRuntimePlugin = (): ModuleFederationRuntimePlugin => {
302309 `[modern-js-v3:rsc-bridge] Remote "${ alias } " is missing the internal RSC bridge expose` ,
303310 ) ;
304311 }
305- return bridge ;
312+ resolveBridge ( bridge ) ;
306313 } )
307314 . catch ( ( error : unknown ) => {
308315 // Allow retry when bridge loading fails transiently.
309316 delete bridgePromises [ alias ] ;
310- throw error ;
317+ rejectBridge ( error ) ;
311318 } ) ;
312- bridgePromises [ alias ] = bridgePromise ;
319+
313320 return bridgePromise ;
314321 } ;
315322
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ const createStaticMiddleware = (options: {
2626 pwd : string ;
2727} ) : MiddlewareHandler => {
2828 const { assetPrefix, pwd } = options ;
29+ const bundlesRootDir = path . resolve ( pwd , `.${ bundlesAssetPrefix } ` ) ;
2930
3031 return async ( c , next ) => {
3132 const pathname = c . req . path ;
@@ -47,7 +48,12 @@ const createStaticMiddleware = (options: {
4748 }
4849
4950 const pathnameWithoutPrefix = pathname . replace ( prefixWithBundle , '' ) ;
50- const filepath = path . join ( pwd , bundlesAssetPrefix , pathnameWithoutPrefix ) ;
51+ const relativeBundlePath = pathnameWithoutPrefix . replace ( / ^ \/ + / , '' ) ;
52+ const filepath = path . resolve ( bundlesRootDir , relativeBundlePath ) ;
53+ const allowedPrefix = `${ bundlesRootDir } ${ path . sep } ` ;
54+ if ( filepath !== bundlesRootDir && ! filepath . startsWith ( allowedPrefix ) ) {
55+ return next ( ) ;
56+ }
5157 if ( ! ( await fs . pathExists ( filepath ) ) ) {
5258 return next ( ) ;
5359 }
You can’t perform that action at this time.
0 commit comments