# 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.

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

## References

* [**Express sendFile API reference**](http://expressjs.com/en/5x/api.html#res.sendFile)
* [**CWE-73: External Control of File Name or Path**](https://cwe.mitre.org/data/definitions/73.html)
* [**OWASP Top 10: A04:2021 - Insecure Design**](https://owasp.org/Top10/A04_2021-Insecure_Design/)

## 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**](https://scopy.sec1.io/login)
