Skip to content

Commit 8bede63

Browse files
committed
fix(component-tests): dynamic import invocation without existence check
A module loader function is resolved from `metaGlobComponents[componentPath]` and invoked without verifying it exists. A crafted route param that does not match a key can result in invoking `undefined`, causing runtime errors and potential repeated 500 responses (DoS-by-error for that endpoint). Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
1 parent 3fda36b commit 8bede63

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

apps/component-tests/src/components/showcase-test/showcase-test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@ export const ShowcaseTest = component$(() => {
1111
const MetaGlobComponentSig = useSignal<Component<any>>();
1212

1313
useTask$(async () => {
14-
MetaGlobComponentSig.value =
15-
await // eslint-disable-next-line @typescript-eslint/no-explicit-any
16-
(metaGlobComponents[componentPath] as () => Promise<Component<any>>)();
14+
const componentLoader = metaGlobComponents[componentPath] as
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
(() => Promise<Component<any>>) | undefined;
17+
18+
if (!componentLoader) {
19+
MetaGlobComponentSig.value = undefined;
20+
return;
21+
}
22+
23+
try {
24+
MetaGlobComponentSig.value = await componentLoader();
25+
} catch {
26+
MetaGlobComponentSig.value = undefined;
27+
}
1728
});
1829

1930
return (

0 commit comments

Comments
 (0)