Skip to content

Commit 22094ea

Browse files
fix: harden mf rsc bundle loading and runtime hooks
1 parent c196826 commit 22094ea

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

packages/modernjs-v3/src/cli/mfRuntimePlugins/rsc-bridge-runtime-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ const rscBridgeRuntimePlugin = (): ModuleFederationRuntimePlugin => {
663663
if (!alias) {
664664
return args;
665665
}
666-
void ensureRemoteAliasMerged(alias, args);
666+
await ensureRemoteAliasMerged(alias, args);
667667
return args;
668668
},
669669
async onLoad(args: any) {

packages/modernjs-v3/src/cli/ssrPlugin.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,25 @@ export const moduleFederationSSRPlugin = (
260260
return;
261261
}
262262
try {
263-
if (
264-
req.url?.includes('.json') &&
265-
!req.url?.includes('hot-update')
266-
) {
267-
const filepath = path.join(process.cwd(), `dist${req.url}`);
263+
const requestPath = req.url?.split('?')[0] || '';
264+
const isJsonRequest = path.extname(requestPath) === '.json';
265+
if (isJsonRequest && !requestPath.includes('hot-update')) {
266+
if (!requestPath.startsWith('/')) {
267+
next();
268+
return;
269+
}
270+
271+
const distRoot = path.resolve(process.cwd(), 'dist');
272+
const filepath = path.resolve(distRoot, `.${requestPath}`);
273+
const allowedPrefix = `${distRoot}${path.sep}`;
274+
if (
275+
filepath !== distRoot &&
276+
!filepath.startsWith(allowedPrefix)
277+
) {
278+
next();
279+
return;
280+
}
281+
268282
fs.statSync(filepath);
269283
res.setHeader('Access-Control-Allow-Origin', '*');
270284
res.setHeader(

packages/server/core/src/adapters/node/plugins/resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const isPromiseLike = (value: unknown): value is Promise<unknown> =>
6565
'then' in (value as Promise<unknown>) &&
6666
typeof (value as Promise<unknown>).then === 'function';
6767

68-
const loadBundleModule = async (filepath: string): Promise<unknown> => {
68+
const loadBundleModule = (filepath: string): unknown | Promise<unknown> => {
6969
try {
7070
return require(filepath);
7171
} catch (err: any) {
@@ -124,7 +124,7 @@ const loadBundle = async (
124124
}
125125

126126
try {
127-
const module = await loadBundleModule(filepath);
127+
const module = loadBundleModule(filepath);
128128
if (!isPromiseLike(module)) {
129129
return module;
130130
}

0 commit comments

Comments
 (0)