External control of filename or path detected.

Description

Passing unsanitized user input to the sendFile API is bad practice and can lead to path manipulation, by which attackers can gain access to resources and data outside of the intended scope.

Remediations

✅ Set the root option to be an absolute path to a directory

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

Resources

Associated CWE

OWASP Top 10