How to fix: Dynamic import() Called With Request-Derived Path
A dynamic import() call's module specifier is built from request params, query, or body data.
Why it matters
Depending on the bundler/runtime, an attacker-controlled import path can load arbitrary local modules (path traversal to unintended code) or, in some Node configurations, fetch and execute a remote module.
AI-generated 'plugin loader' or 'dynamic page loader' code sometimes builds the import() specifier directly from a route parameter for convenience, without restricting it to a fixed allowlist of known-safe module names.
How to fix it
- 1Map the request-derived value to a fixed allowlist of module names/paths instead of interpolating it into the import specifier directly.
- 2Reject any value containing path traversal sequences or characters outside an expected identifier pattern.
- 3Prefer a static switch/lookup table over dynamic import() when the set of loadable modules is known in advance.
Code examples
Allowlist instead of dynamic path
const MODULES: Record<string, () => Promise<unknown>> = {
invoice: () => import('./plugins/invoice'),
receipt: () => import('./plugins/receipt'),
};
const loader = MODULES[req.params.plugin];
if (!loader) throw new Error('Unknown plugin');
const mod = await loader();References
Detected automatically by VulnRadar. The check id is vibe-dynamic-import-user-input, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- Higheval() Usage in Page Scripts
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
Questions
- How severe is Dynamic import() Called With Request-Derived Path?
- VulnRadar rates this high severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vibe-dynamic-import-user-input, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.