Unsanitized user input in HTTP send file request

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 be able to, by manipulating file paths in requests.

Remediations

  • Do set the root option to an absolute path to a directory when using sendFile. This confines the 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

Associated CWE

OWASP Top 10

Configuration

To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=javascript_express_external_file_upload

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=javascript_express_external_file_upload