Web Security · Middle · Question 67 of 75

How do you prevent path traversal in a file download endpoint?

res.sendFile(path.join(UPLOADS, req.query.name));

Explanation

../../etc/passwd and encoded variants escape the folder. Checking the resolved absolute path or avoiding user paths entirely is reliable.

Further reading

Problem with a question

Web Security · Middle · question 67

Test yourself

Take the Web Security · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz