{"id":"CVE-2026-40163","aliases":["CVE-2026-40163","GHSA-32pv-mpqg-h292"],"related":[],"kind":"vulnerability","state":"published","title":"Saltcorn has an Unauthenticated Path Traversal in sync endpoints allows arbitrary file write and directory read","summary":"Saltcorn is an extensible, open source, no-code database application builder. Prior to 1.4.5, 1.5.5, and 1.6.0-beta.4, the POST /sync/offline_changes endpoint allows an unauthenticated attacker to create arbitrary directories and write a changes.json file with attacker-controlled JSON content anywhere on the server filesystem. The GET /sync/upload_finished endpoint allows an unauthenticated attacker to list arbitrary directory contents and read specific JSON files. This vulnerability is fixed in 1.4.5, 1.5.5, and 1.6.0-beta.4.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Saltcorn is an extensible, open source, no-code database application builder. Prior to 1.4.5, 1.5.5, and 1.6.0-beta.4, the POST /sync/offline_changes endpoint allows an unauthenticated attacker to create arbitrary directories and write a changes.json file with attacker-controlled JSON content anywhere on the server filesystem. The GET /sync/upload_finished endpoint allows an unauthenticated attacker to list arbitrary directory contents and read specific JSON files. This vulnerability is fixed in 1.4.5, 1.5.5, and 1.6.0-beta.4.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nTwo unauthenticated path traversal vulnerabilities exist in Saltcorn's mobile sync endpoints. The `POST /sync/offline_changes` endpoint allows an unauthenticated attacker to create arbitrary directories and write a `changes.json` file with attacker-controlled JSON content anywhere on the server filesystem. The `GET /sync/upload_finished` endpoint allows an unauthenticated attacker to list arbitrary directory contents and read specific JSON files.\n\nThe safe path validation function `File.normalise_in_base()` exists in the codebase and is correctly used by the `clean_sync_dir` endpoint in the **same file** (fix for GHSA-43f3-h63w-p6f6), but was not applied to these two endpoints.\n\n### Details\n\n**Finding 1: Arbitrary file write — `POST /sync/offline_changes` (sync.js line 226)**\n\nThe `newSyncTimestamp` parameter from the request body is used directly in `path.join()` without sanitization:\n\n```javascript\nconst syncDirName = `${newSyncTimestamp}_${req.user?.email || \"public\"}`;\nconst syncDir = path.join(\n    rootFolder.location, \"mobile_app\", \"sync\", syncDirName\n);\nawait fs.mkdir(syncDir, { recursive: true });        // creates arbitrary dir\nawait fs.writeFile(\n    path.join(syncDir, \"changes.json\"),\n    JSON.stringify(changes)                           // writes attacker content\n);\n```\n\nNo authentication middleware is applied to this route. Since `path.join()` normalizes `../` sequences, setting `newSyncTimestamp` to `../../../../tmp/evil` causes the path to resolve outside the sync directory.\n\n**Finding 2: Arbitrary directory read — `GET /sync/upload_finished` (sync.js line 288)**\n\nThe `dir_name` query parameter is used directly in `path.join()` without sanitization:\n\n```javascript\nconst syncDir = path.join(\n    rootFolder.location, \"mobile_app\", \"sync\", dir_name\n);\nlet entries = await fs.readdir(syncDir);\n```\n\nAlso unauthenticated. An attacker can list directory contents and read files named `translated-ids.json`, `unique-conflicts.json`, `data-conflicts.json`, or `error.json` from any directory.\n\n**Contrast — fixed endpoint in the same file (line 342):**\n\nThe `clean_sync_dir` endpoint correctly uses `File.normalise_in_base()`:\n\n```javascript\nconst syncDir = File.normalise_in_base(\n    path.join(rootFolder.location, \"mobile_app\", \"sync\"),\n    dir_name\n);\nif (syncDir) await fs.rm(syncDir, { recursive: true, force: true });\n```\n\n### PoC\n\n```bash\n# Write arbitrary file to /tmp/\ncurl -X POST http://TARGET:3000/sync/offline_changes \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"newSyncTimestamp\": \"../../../../tmp/saltcorn_poc\",\n    \"oldSyncTimestamp\": \"0\",\n    \"changes\": {\"proof\": \"path_traversal_write\"}\n  }'\n# Result: /tmp/saltcorn_poc_public/changes.json created with attacker content\n\n# List /etc/ directory\ncurl \"http://TARGET:3000/sync/upload_finished?dir_name=../../../../etc\"\n```\n\n### Impact\n\n- **Unauthenticated arbitrary directory creation** anywhere on the filesystem\n- **Unauthenticated arbitrary JSON file write** (`changes.json`) to any writable directory\n- **Unauthenticated directory listing** of arbitrary directories\n- **Unauthenticated read** of specific JSON files from arbitrary directories\n- Potential for **remote code execution** via writing to sensitive paths (cron, systemd, Node.js module paths)\n\n### Remediation\n\nApply `File.normalise_in_base()` to both endpoints, matching the existing pattern in `clean_sync_dir`:\n\n```javascript\n// offline_changes fix\nconst syncDirName = `${newSyncTimestamp}_${req.user?.email || \"public\"}`;\nconst syncDir = File.normalise_in_base(\n    path.join(rootFolder.location, \"mobile_app\", \"sync\"),\n    syncDirName\n);\nif (!syncDir) {\n    return res.status(400).json({ error: \"Invalid sync directory name\" });\n}\n\n// upload_finished fix\nconst syncDir = File.normalise_in_base(\n    path.join(rootFolder.location, \"mobile_app\", \"sync\"),\n    dir_name\n);\nif (!syncDir) {\n    return res.json({ finished: false });\n}\n```\n\nAdditionally, add `loggedIn` middleware to endpoints that modify server state.","format":"markdown","source":"ghsa"}],"published":"2026-04-10T17:07:49.067Z","modified":"2026-06-17T10:44:47.933Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N","score":8.2,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N","score":8.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N","score":8.2,"rating":"HIGH"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":"< 1.4.5","status":"affected"},{"version":">= 1.5.0-beta.0, < 1.5.5","status":"affected"},{"version":">= 1.6.0-alpha.0, < 1.6.0-beta.4","status":"affected"}],"vendor":"saltcorn","product":"saltcorn","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"1.4.5"}],"ecosystem":"npm","package":"@saltcorn/server","purl":"pkg:npm/%40saltcorn/server","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"1.5.0-beta.0","status":"affected","fixed":"1.5.5"}],"ecosystem":"npm","package":"@saltcorn/server","purl":"pkg:npm/%40saltcorn/server","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"1.6.0-alpha.0","status":"affected","fixed":"1.6.0-beta.4"}],"ecosystem":"npm","package":"@saltcorn/server","purl":"pkg:npm/%40saltcorn/server","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"1.4.5"},{"status":"affected","introduced":"1.5.0","fixed":"1.5.5"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"},{"status":"affected","version":"1.6.0"}],"vendor":"saltcorn","product":"saltcorn","cpe":"cpe:2.3:a:saltcorn:saltcorn:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/saltcorn/saltcorn/security/advisories/GHSA-32pv-mpqg-h292","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40163","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/saltcorn/saltcorn","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-04-15T14:49:25.336Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-40163","url":"https://www.cve.org/CVERecord?id=CVE-2026-40163","licence":"CVE Terms of Use","modified":"2026-04-15T14:50:01.616Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-32pv-mpqg-h292","url":"https://github.com/advisories/GHSA-32pv-mpqg-h292","licence":"CC-BY-4.0","modified":"2026-04-10T19:56:21.826Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-40163","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40163","licence":"Public domain","modified":"2026-06-17T10:44:47.933Z"}],"updatedAt":"2026-11-25T22:59:18.536Z","epss":{"score":0.00347,"percentile":0.30261,"date":"2026-12-01T12:00:22.000Z"}}