Languages
[Edit]
EN

Node.js - resolve path and prevent access above parent directory

3 points
Created by:
Creg
9600

In this article, we would like to show simple way how to resolve path and prevent access above parent directory in Node.js.

It is common to resolve paths on server side in web applications. Simetimes it is necessary to send path as a API parameter what may be dangerous. In that case we need to control the parameter that contains .., ../.., ../../.., etc. The solution for the problem is to use resolve() and startsWith() methods what was show in the next section.

Practical example

Edit

In this section you will find reusable tool that may be used to resolve paths preventing access above parent directory.

script.js file:

 

Alternative solution

Edit

 

Alternative titles

  1. Node.js - resolve path and protect access above parent directory
  2. Node.js - resolve path and block access above parent directory
  3. Node.js - resolve path and prevent access over parent directory
  4. Node.js - resolve path and protect access over parent directory
  5. Node.js - resolve path and block access over parent directory
  6. Node.js - resolve path and prevent access above base directory
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join