GHSA-277h-px4m-62q8: @saltcorn/server @saltcorn/server Arbitrary File Zip Read Vulnerability

MODERATE
CVSS 4.4
CWE-22
Published
Advisory Summary

GHSA-277h-px4m-62q8 is a MODERATE (CVSS 4.4) @saltcorn/server arbitrary file zip read 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 arbitrary file zip read and download when downloading auto backups. Remediation is available by upgrading affected packages to version 1.0.0-beta.14.

GHSA-277h-px4m-62q8 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-277h-px4m-62q8
Severity MODERATE
CVSS v3.1 Base Score 4.4
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: 4.4

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

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

How to Fix GHSA-277h-px4m-62q8

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.14
npm install @saltcorn/server@1.0.0-beta.14
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 GHSA-277h-px4m-62q8, 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.14), 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 user with admin permission can read and download arbitrary zip files when downloading auto backups. The file name used to identify the zip file is not properly sanitized when passed to `res.download` API. ### Details - file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/admin.js#L671-L682 ```js router.get( "/auto-backup-download/:filename", isAdmin, error_catcher(async (req, res) => { const { filename } = req.params; // [1] source [...] if ( !isRoot || !(filename.startsWith(backup_file_prefix) && filename.endsWith(".zip")) // [2] ) { res.redirect("/admin/backup"); return; } const auto_backup_directory = getState().getConfig("auto_backup_directory"); res.download(path.join(auto_backup_directory, filename), filename); // [3] sink }) ); ``` ### Steps to reproduce (PoC) - create a file with `.zip` extension under `/tmp` folder: ``` echo "secret12345" > /tmp/secret.zip ``` - log into the application as an admin user - visit the url `http://localhost:3000/admin/auto-backup-download/sc-backup-%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2ftmp%2fsecret.zip` - download the zip file and then check if the zip was indeed downloaded: ```bash cat secret.zip secret12345 ``` - Alternatively send the following request to retrieve the file just created. ```bash curl -i -X $'GET' \ -H $'Host: localhost:3000' \ -H $'Connection: close' \ -b $'connect.sid=VALID_CONNECT_SID_COOKIE' \ $'http://localhost:3000/admin/auto-backup-download/sc-backup-%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2ftmp%2fsecret.zip' ``` **NOTE**: To obtain a valid `connect.sid` cookie, just open the developer console while logged and retrieve the cookie value. ### Impact Arbitrary zip files download (information disclosure). ### Recommended Mitigation Resolve the `filename` parameter before checking if it starts with `backup_file_prefix` .

GHSA-277h-px4m-62q8 Affected @saltcorn/server Versions

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

References

Frequently Asked Questions

What is GHSA-277h-px4m-62q8?
GHSA-277h-px4m-62q8 is a security vulnerability in @saltcorn/server involving @saltcorn/server arbitrary file zip read and download when downloading auto backups 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.14 across affected packages: @saltcorn/server.
What version fixes GHSA-277h-px4m-62q8?
Upgrading to 1.0.0-beta.14 (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.14. Upgrade your dependency to 1.0.0-beta.14 or later.
What is the CVSS score of GHSA-277h-px4m-62q8?
GHSA-277h-px4m-62q8 has a CVSS v3.1 base score of 4.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with GHSA-277h-px4m-62q8?
GHSA-277h-px4m-62q8 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 GHSA-277h-px4m-62q8?
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-277h-px4m-62q8",
  "modified" : "2024-10-03T19:46:12Z",
  "published" : "2024-10-03T19:46:12Z",
  "aliases" : [ ],
  "summary" : "@saltcorn/server arbitrary file zip read and download when downloading auto backups",
  "details" : "### Summary\n\nA user with admin permission can read and download arbitrary zip files when downloading auto backups. The file name used to identify the zip file is not properly sanitized when passed to `res.download` API.\n\n### Details\n\n- file: https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/admin.js#L671-L682\n\n```js\nrouter.get(\n  \"/auto-backup-download/:filename\",\n  isAdmin,\n  error_catcher(async (req, res) => {\n    const { filename } = req.params; // [1] source\n    [...]\n    if (\n      !isRoot ||\n      !(filename.startsWith(backup_file_prefix) && filename.endsWith(\".zip\")) // [2]\n    ) {\n      res.redirect(\"/admin/backup\");\n      return;\n    }\n    const auto_backup_directory = getState().getConfig(\"auto_backup_directory\");\n    res.download(path.join(auto_backup_directory, filename), filename); // [3] sink\n  })\n);\n```\n\n### Steps to reproduce (PoC)\n\n- create a file with `.zip` extension under `/tmp` folder:\n```\necho \"secret12345\" > /tmp/secret.zip\n```\n- log into the application as an admin user\n- visit the url   `http://localhost:3000/admin/auto-backup-download/sc-backup-%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2ftmp%2fsecret.zip`\n- download the zip file and then check if the zip was indeed downloaded:\n```bash\ncat secret.zip\nsecret12345\n```\n\n \n- Alternatively send the following request to retrieve the file just created.\n```bash\ncurl -i -X $'GET' \\\n    -H $'Host: localhost:3000' \\\n    -H $'Connection: close' \\\n    -b $'connect.sid=VALID_CONNECT_SID_COOKIE' \\\n    $'http://localhost:3000/admin/auto-backup-download/sc-backup-%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2ftmp%2fsecret.zip'\n```\n\n**NOTE**:\nTo obtain a valid `connect.sid` cookie, just open the developer console while logged and retrieve the cookie value.\n\n### Impact\n\nArbitrary zip files download (information disclosure).\n\n### Recommended Mitigation\n\nResolve the `filename` parameter before checking if it starts with `backup_file_prefix` .",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:H/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:H/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:P"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@saltcorn/server"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.0-beta.14"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.0.0-beta.13"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/security/advisories/GHSA-277h-px4m-62q8"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/commit/024f19a7e079913f62f4a2335ab04116ddb68192"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/saltcorn/saltcorn"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/saltcorn/saltcorn/blob/v1.0.0-beta.13/packages/server/routes/admin.js#L671-L682"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-03T19:46:12Z",
    "nvd_published_at" : null
  }
}