Vulnerabilities in pkg:npm/import-in-the-middle

PACKAGE
Advisory Identifier: GHSA-5r27-rw8r-7967
Advisory Summary

CVE-2023-38704 is a HIGH (CVSS 8.1) import-in-the-middle has unsanitized user controlled vulnerability (CWE-20: Improper Input Validation) affecting Import in the middle libraries in the npm ecosystem. The issue involves import-in-the-middle has unsanitized user controlled input in module generation. Remediation is available by upgrading affected packages to version 1.4.2.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/import-in-the-middle

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/import-in-the-middle. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-5r27-rw8r-7967 CVE-2023-38704 HIGH import-in-the-middle has unsanitized user controlled input in module generation

CVE-2023-38704 at a Glance

CVE Identifier CVE-2023-38704
GHSA Identifier GHSA-5r27-rw8r-7967
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-20: Improper Input Validation
Affected Product Import in the middle
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:L).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2023-38704

To remediate this vulnerability, upgrade all affected Import in the middle dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

import-in-the-middle fixed: 1.4.2
npm install import-in-the-middle@1.4.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls import-in-the-middle

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2023-38704, inspect your project dependencies using npm:

npm ls import-in-the-middle

Analyze the terminal output to locate any version of Import in the middle in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.4.2), your application is affected.

Note: The npm ls import-in-the-middle command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In Import in the middle, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 `NODE_OPTIONS` 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](mailto:security@datadoghq.com)

CVE-2023-38704 Affected Import in the middle Versions

1 component(s)
Fixed Versions:
1.4.2
Product / Package Ecosystem Affected Versions Fixed Version
import-in-the-middle
npm
< 1.4.2
1.4.2

References

Frequently Asked Questions

What is CVE-2023-38704?
CVE-2023-38704 is a security vulnerability in Import in the middle involving import-in-the-middle has unsanitized user controlled input in module generation under CWE-20: Improper Input Validation.
Which Import in the middle versions are affected?
Affected versions include releases prior to 1.4.2 across affected packages: import-in-the-middle.
What version fixes CVE-2023-38704?
Upgrading to 1.4.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is import-in-the-middle affected?
Yes, import-in-the-middle is affected in releases prior to 1.4.2. Upgrade your dependency to 1.4.2 or later.
What is the CVSS score of CVE-2023-38704?
CVE-2023-38704 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:L.
What CWE is associated with CVE-2023-38704?
CVE-2023-38704 is classified under CWE-20: Improper Input Validation (The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.).
How can I check npm dependencies for CVE-2023-38704?
Run the dependency tree command: 'npm ls import-in-the-middle'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5r27-rw8r-7967",
  "modified" : "2023-08-14T13:14:54Z",
  "published" : "2023-08-08T19:26:40Z",
  "aliases" : [ "CVE-2023-38704" ],
  "summary" : "import-in-the-middle has unsanitized user controlled input in module generation",
  "details" : "### Impact\nThe `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.\n\n### Patches\nThis vulnerability has been patched in `import-in-the-middle` version 1.4.2\n\n### Workarounds\n* Do not pass any user-supplied input to `import()`. Instead, verify it against a set of allowed values.\n* 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 `NODE_OPTIONS` environment variable):\n```\n--loader=import-in-the-middle/hook.mjs\n--loader import-in-the-middle/hook.mjs\n```\n\n### References\nIf you have any questions or comments about this advisory, email us at [security@datadoghq.com](mailto:security@datadoghq.com)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "import-in-the-middle"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.4.2"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.4.1"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/DataDog/import-in-the-middle/security/advisories/GHSA-5r27-rw8r-7967"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-38704"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/DataDog/import-in-the-middle/commit/2531cdd9d1d73f9eaa87c16967f60cb276c1971b"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/DataDog/import-in-the-middle"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-08T19:26:40Z",
    "nvd_published_at" : "2023-08-07T20:15:09Z"
  }
}