You can't change how Node.js interpret the code unless you write/change the interpreter yourself. You can use linters like ESlint with the no-eval rule to make sure there is none in your code if it is not required.
eval
is not in and of itself evil. It does serve some legit purposes.
It is only unsafe when you use it in an unsafe manner.
It's like a cooking knife. It is safe when you use it properly and use it for what it is made to do. If you try to pick your teeth with it, you can. But it is probably not a good idea.
What you are asking now is like asking how can you not let a knife be sharp because it can potentially cut you.
There are other more important things to worry about.
- Is your server secure without misconfiguration?
- Did you actually install the right packages not some malicious ones with similar names waiting for you to make a typo?
- Did you check the package content before just running
npm i
?
- Did you accidentally commit sensitive information to your version control?
- Is your database secured? Is it accidentally configured to be internet-facing while it should not be?
Just to name a few. There are hundreds perhaps thousands of other points that you should worry about in terms of the overall security of your system.
Side Note:
For 0-day vulnerabilities, you can only pray.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…