Node.js · Senior · Question 28 of 75

How do you safely serve a user-requested file from an uploads directory?

Explanation

Path traversal can use encodings or absolute paths, so a single replace isn't enough. Better still, store files by generated IDs and keep names in the database.

Further reading

Problem with a question

Node.js · Senior · question 28

Test yourself

Take the Node.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz