CVE-2023-38704

8.1 HIGH

📋 TL;DR

CVE-2023-38704 is a remote code execution vulnerability in import-in-the-middle, a module loading interceptor for ESM modules. It allows attackers to execute arbitrary code when user-supplied input is passed directly to the import() function. This affects applications using vulnerable versions of import-in-the-middle, particularly those that dynamically import modules based on user input.

💻 Affected Systems

Products:
  • import-in-the-middle
Versions: All versions prior to 1.4.2
Operating Systems: All operating systems running Node.js with ESM support
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects applications that use import-in-the-middle and pass user input to import(). Applications using CommonJS modules exclusively are not affected.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise allowing attackers to execute arbitrary code with application privileges, potentially leading to data theft, system takeover, or lateral movement.

🟠

Likely Case

Remote code execution leading to application compromise, data exfiltration, or deployment of malware/backdoors.

🟢

If Mitigated

No impact if user input is properly validated or the vulnerability is patched.

🌐 Internet-Facing: HIGH - Web applications accepting user input that gets passed to import() are directly exploitable from the internet.
🏢 Internal Only: MEDIUM - Internal applications could be exploited by authenticated users or through other attack vectors.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: UNKNOWN
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW - Exploitation requires only passing malicious input to import() function.

The vulnerability is straightforward to exploit if an application passes unsanitized user input to import().

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 1.4.2

Vendor Advisory: https://github.com/DataDog/import-in-the-middle/security/advisories/GHSA-5r27-rw8r-7967

Restart Required: Yes

Instructions:

1. Update import-in-the-middle to version 1.4.2 or later using npm update import-in-the-middle. 2. Restart the Node.js application. 3. Verify the update with npm list import-in-the-middle.

🔧 Temporary Workarounds

Input validation

all

Do not pass user-supplied input directly to import(). Validate against a whitelist of allowed module names.

Disable ESM loader hooks

all

If ESM support is not needed, ensure no loader hooks are enabled via command-line or NODE_OPTIONS environment variable.

unset NODE_OPTIONS
Remove --loader or --experimental-loader flags from Node.js startup

🧯 If You Can't Patch

  • Implement strict input validation for any data passed to import() functions
  • Disable import-in-the-middle by removing it from dependencies or disabling loader hooks

🔍 How to Verify

Check if Vulnerable:

Check package.json or run npm list import-in-the-middle to see if version is below 1.4.2

Check Version:

npm list import-in-the-middle | grep import-in-the-middle

Verify Fix Applied:

Confirm import-in-the-middle version is 1.4.2 or higher with npm list import-in-the-middle

📡 Detection & Monitoring

Log Indicators:

  • Unusual module import attempts
  • Import errors with unexpected module names
  • Process spawning from Node.js application

Network Indicators:

  • Unexpected outbound connections from Node.js process
  • Data exfiltration patterns

SIEM Query:

process.name:node AND (process.cmdline:*import* OR process.cmdline:*--loader*)

🔗 References

📤 Share & Export