CVE-2024-39918: @jmondi/url to png Path Traversal Vulnerability

MODERATE
Advisory Identifier: GHSA-vvmv-wrvp-9gjr
CVSS 5.3
CWE-22
Published
Advisory Summary

CVE-2024-39918 is a MODERATE (CVSS 5.3) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting @jmondi/url to png libraries in the npm ecosystem. The issue involves @jmondi/url-to-png contains a path traversal vulnerability. Remediation is available by upgrading affected packages to version 2.1.2.

CVE-2024-39918 at a Glance

CVE Identifier CVE-2024-39918
GHSA Identifier GHSA-vvmv-wrvp-9gjr
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product @jmondi/url to png
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.3

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

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

How to Fix CVE-2024-39918

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

@jmondi/url-to-png fixed: 2.1.2
npm install @jmondi/url-to-png@2.1.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 @jmondi/url-to-png

How to Check if You Are Affected

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

npm ls @jmondi/url-to-png

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

Note: The npm ls @jmondi/url-to-png 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-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In @jmondi/url to png, 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 When trying to add a `BLOCK_LIST` feature when the maintainer noticed they didn't sanitize the `ImageId` in the code, which leads to path traversal vulnerability. Now, this is different from a traditional path traversal issue, because as of NOW you can store the image in any place arbitrarily, and given enough time they might be able to come up with a working exploit BUT for the time being they am reporting this. ### Details @jmondi/url-to-png does not sanitizing the `ImageID` as in not removing special chars from the params [(extract_query_params.ts#l75)](https://github.com/jasonraimondi/url-to-png/blob/e43098e0af3a380ebc044e7f303a83933b94b434/src/middlewares/extract_query_params.ts#L75) ```js const imageId = dateString + "." + slugify(validData.url) +configToString(params); ``` This when fed to other parts of the code such as ([filesystem.ts#L34](https://github.com/jasonraimondi/url-to-png/blob/8afc00247c1d7e6c7b37356a5f6282b486e596fa/src/lib/storage/filesystem.ts#L34)) ```js return path.join(this.storagePath, imageId) + ".png"; ``` Would result in path traversal issue. ### PoC ``` # Configuration for filesystem storage provider (optional) STORAGE_PROVIDER=filesystem IMAGE_STORAGE_PATH=poc ``` Set this in your `.env` file and use this as your payload. ``` http://localhost:3089/?url=http://example.com&width=400&isDarkMode=../../../../../../../../../../../../tmp/hack ``` This will create a `.png` file in the `/tmp` section of the system. Loom POC: https://www.loom.com/share/bd7b306cdae7445c97e68f0626e743a6 This is valid for pretty much all the arguments (except for numeric values) A simple fix would be to use the `slugify` for the params as well like so ([#L75](https://github.com/jasonraimondi/url-to-png/blob/e43098e0af3a380ebc044e7f303a83933b94b434/src/middlewares/extract_query_params.ts#L75)) ```diff - const imageId = dateString + "." + slugify(validData.url) + configToString(params); + const imageId = dateString + "." + slugify(validData.url) + slugify(configToString(params)); ``` ### Impact This would be path traversal vulnerability which allows arbitrary write as of now.

CVE-2024-39918 Affected @jmondi/url to png Versions

1 component(s)
Fixed Versions:
2.1.2
Product / Package Ecosystem Affected Versions Fixed Version
@jmondi/url-to-png
npm
< 2.1.2
2.1.2

References

Frequently Asked Questions

What is CVE-2024-39918?
CVE-2024-39918 is a security vulnerability in @jmondi/url to png involving @jmondi/url-to-png contains a Path Traversal vulnerability under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which @jmondi/url to png versions are affected?
Affected versions include releases prior to 2.1.2 across affected packages: @jmondi/url-to-png.
What version fixes CVE-2024-39918?
Upgrading to 2.1.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @jmondi/url-to-png affected?
Yes, @jmondi/url-to-png is affected in releases prior to 2.1.2. Upgrade your dependency to 2.1.2 or later.
What is the CVSS score of CVE-2024-39918?
CVE-2024-39918 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N.
What CWE is associated with CVE-2024-39918?
CVE-2024-39918 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check npm dependencies for CVE-2024-39918?
Run the dependency tree command: 'npm ls @jmondi/url-to-png'. 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-vvmv-wrvp-9gjr",
  "modified" : "2024-07-15T21:38:34Z",
  "published" : "2024-07-15T17:46:57Z",
  "aliases" : [ "CVE-2024-39918" ],
  "summary" : "@jmondi/url-to-png contains a Path Traversal vulnerability",
  "details" : "### Summary\nWhen trying to add a `BLOCK_LIST` feature when the maintainer noticed they didn't sanitize the `ImageId` in the code, which leads to path traversal vulnerability. Now, this is different from a traditional path traversal issue, because as of NOW you can store the image in any place arbitrarily, and given enough time they might be able to come up with a working exploit BUT for the time being they am reporting this.  \n\n### Details\n\n@jmondi/url-to-png does not sanitizing the `ImageID` as in not removing special chars from the params [(extract_query_params.ts#l75)](https://github.com/jasonraimondi/url-to-png/blob/e43098e0af3a380ebc044e7f303a83933b94b434/src/middlewares/extract_query_params.ts#L75)\n\n```js\nconst imageId = dateString + \".\" + slugify(validData.url) +configToString(params);\n```\n\nThis when fed to other parts of the code such as ([filesystem.ts#L34](https://github.com/jasonraimondi/url-to-png/blob/8afc00247c1d7e6c7b37356a5f6282b486e596fa/src/lib/storage/filesystem.ts#L34))\n\n```js\nreturn path.join(this.storagePath, imageId) + \".png\";\n```\n\nWould result in path traversal issue. \n\n### PoC\n\n```\n# Configuration for filesystem storage provider (optional)\nSTORAGE_PROVIDER=filesystem\nIMAGE_STORAGE_PATH=poc\n```\n\nSet this in your `.env` file and use this as your payload. \n\n```\nhttp://localhost:3089/?url=http://example.com&width=400&isDarkMode=../../../../../../../../../../../../tmp/hack\n```\n\nThis will create a `.png` file in the `/tmp` section of the system.\n\nLoom POC: https://www.loom.com/share/bd7b306cdae7445c97e68f0626e743a6 \n\n\n\nThis is valid for pretty much all the arguments (except for numeric values)\n\nA simple fix would be to use the `slugify` for the params as well like so ([#L75](https://github.com/jasonraimondi/url-to-png/blob/e43098e0af3a380ebc044e7f303a83933b94b434/src/middlewares/extract_query_params.ts#L75))\n\n```diff\n- const imageId = dateString + \".\" + slugify(validData.url) + configToString(params);\n+ const imageId = dateString + \".\" + slugify(validData.url) + slugify(configToString(params));\n```\n\n\n### Impact\nThis would be path traversal vulnerability which allows arbitrary write as of now. \n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@jmondi/url-to-png"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.1.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/jasonraimondi/url-to-png/security/advisories/GHSA-vvmv-wrvp-9gjr"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-39918"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jasonraimondi/url-to-png/commit/e4eaeca6493b21cd515b582fd6c0af09ede54507"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/jasonraimondi/url-to-png"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jasonraimondi/url-to-png/blob/e43098e0af3a380ebc044e7f303a83933b94b434/src/middlewares/extract_query_params.ts#L75"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jasonraimondi/url-to-png/releases/tag/v2.1.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-15T17:46:57Z",
    "nvd_published_at" : "2024-07-15T20:15:04Z"
  }
}