Skip to content

Commit 5762be3

Browse files
committed
refactor(rsc-mf): validate remote alias before bridge action prefixing
1 parent f8e30d1 commit 5762be3

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

tests/integration/rsc-mf/remote/src/runtime/registerServerCallback.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@ export function registerRemoteServerCallback(
2828
if (!remoteOrigin) {
2929
return;
3030
}
31+
const normalizedRemoteAlias = remoteAlias.trim();
32+
if (!normalizedRemoteAlias || normalizedRemoteAlias.includes(':')) {
33+
throw new Error(
34+
`Remote alias must be a non-empty identifier without ":" delimiters. Received: ${remoteAlias}`,
35+
);
36+
}
3137
const remoteActionUrl = getNormalizedRemoteActionUrl(remoteOrigin);
3238
const callbackKey = JSON.stringify({
33-
remoteAlias,
39+
remoteAlias: normalizedRemoteAlias,
3440
remoteActionUrl,
3541
});
3642
if (registeredCallbackKey === callbackKey) {
3743
return;
3844
}
3945

4046
setServerCallback(async (id, args) => {
41-
const hostActionId = getHostActionId(id, remoteAlias);
47+
const hostActionId = getHostActionId(id, normalizedRemoteAlias);
4248
const temporaryReferences = createTemporaryReferenceSet();
4349
const response = fetch(remoteActionUrl, {
4450
method: 'POST',

tests/integration/rsc-mf/tests/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,15 @@ function runTests({ mode }: TestConfig) {
618618
expect(runtimeRegisterSource).not.toContain('127.0.0.1:');
619619
expect(runtimeRegisterSource).not.toContain('window.location');
620620
expect(runtimeRegisterSource).toContain("remoteAlias = 'rscRemote'");
621+
expect(runtimeRegisterSource).toContain(
622+
'const normalizedRemoteAlias = remoteAlias.trim()',
623+
);
624+
expect(runtimeRegisterSource).toContain(
625+
"!normalizedRemoteAlias || normalizedRemoteAlias.includes(':')",
626+
);
627+
expect(runtimeRegisterSource).toContain(
628+
'Remote alias must be a non-empty identifier without ":" delimiters',
629+
);
621630
expect(runtimeRegisterSource).toContain(
622631
"if (rawActionId.startsWith('remote:'))",
623632
);
@@ -630,7 +639,16 @@ function runTests({ mode }: TestConfig) {
630639
expect(runtimeRegisterSource).toContain('getNormalizedRemoteActionUrl');
631640
expect(runtimeRegisterSource).toContain("url.search = ''");
632641
expect(runtimeRegisterSource).toContain("url.hash = ''");
642+
expect(runtimeRegisterSource).toContain(
643+
'remoteAlias: normalizedRemoteAlias',
644+
);
645+
expect(runtimeRegisterSource).toContain(
646+
'getHostActionId(id, normalizedRemoteAlias)',
647+
);
633648
expect(runtimeRegisterSource).toContain('remoteActionUrl,');
649+
expect(runtimeRegisterSource).not.toContain(
650+
'getHostActionId(id, remoteAlias)',
651+
);
634652
expect(runtimeRegisterSource).not.toContain(
635653
'remoteActionIdToHostProxyActionId',
636654
);

0 commit comments

Comments
 (0)