Unsanitized User input in HTTP Send file request

Overview

  • Rule ID: javascript_express_external_file_upload

  • Applicable Languages: Javascript

  • Weakness ID: CWE-73

Description

Using unsanitized user input in the sendFile API call exposes your application to path manipulation attacks. This vulnerability allows attackers to access files and resources they shouldn't by manipulating file paths in requests.

Remediation Guidelines

  • Set the root option to an absolute path when using sendFile. This restricts accessible files to a specific directory, preventing attackers from accessing files outside of this directory.

    app.post("/upload", (req, res) => {
       var options = {
         root: path.join(__dirname, "upload")
       };
       res.sendFile(req.params.filename, options);
    });

References

Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our SAST TOOL

Last updated