CVE-2023-38704: import-in-the-middle allows unsanitized user controlled input in module generation
Impact The import-in-the-middle loader works by generating a wrapper module on the fly. The wrapper uses the module specifier to load the original module and add some wrapping code. It allows for remote code execution in cases where an application passes user-supplied input directly to an import() function.
Patches This vulnerability has been patched in import-in-the-middle version 1.4.2
Workarounds Do not pass any user-supplied input to import(). Instead, verify it against a set of allowed values. If using import-in-the-middle and support for EcmaScript Modules is not needed, ensure that none of the following options are set (either via command-line or the NODEOPTIONS environment variable): --loader=import-in-the-middle/hook.mjs --loader import-in-the-middle/hook.mjs
References If you have any questions or comments about this advisory, email us at security@datadoghq.com
Other sources
import-in-the-middle is a module loading interceptor specifically for ESM modules. The import-in-the-middle loader works by generating a wrapper module on the fly. The wrapper uses the module specifier to load the original module and add some wrapping code. Prior to version 1.4.2, it allows for remote code execution in cases where an application passes user-supplied input directly to the import() function. This vulnerability has been patched in import-in-the-middle version 1.4.2.
Some workarounds are available. Do not pass any user-supplied input to import(). Instead, verify it against a set of allowed values. If using import-in-the-middle, directly or indirectly, and support for EcmaScript Modules is not needed, ensure that no options are set, either via command-line or the NODEOPTIONS environment variable, that would enable loader hooks.
Affected Software
Remediation
Event History
Frequently Asked Questions
What is CVE-2023-38704?
CVE-2023-38704 is a vulnerability in import-in-the-middle, a module loading interceptor for ESM modules.
What is the impact of CVE-2023-38704?
The impact of CVE-2023-38704 is remote code execution when an application passes user-supplied input directly to an import statement.
What is the severity of CVE-2023-38704?
The severity of CVE-2023-38704 is critical with a CVSS score of 9.8.
Which software is affected by CVE-2023-38704?
The affected software is import-in-the-middle version 1.4.2 and below for Node.js and npm/import-in-the-middle version 1.4.1.
How can CVE-2023-38704 be fixed?
To fix CVE-2023-38704, update import-in-the-middle to version 1.4.3 or later for Node.js, and update npm/import-in-the-middle to version 1.4.2 or later.