简体   繁体   English

NodeJS和NPM:包安全性

[英]NodeJS & NPM: Package Security

Given how popular NodeJS is, and how NPM works... what is the best way to ensure you never install an insecure / malware package? 鉴于NodeJS的流行程度以及NPM的工作原理......确保您永远不会安装不安全/恶意软件包的最佳方法是什么? To me this seems to be a huge gaping hole in the architecture, relying solely on user reviews, comments on sites like StackOverflow, personal blogs, etc. I've done a little searching and all I can seem to find is a "plan" for removing offending users once a complaint is filed that said users broke the code of conduct. 对我而言,这似乎是架构中一个巨大的漏洞,完全依赖于用户评论,对StackOverflow等网站的评论,个人博客等等。我做了一些搜索,我似乎找到的只是一个“计划”一旦提出投诉,说用户违反了行为准则,就会删除违规用户。

NPM Code of Conduct https://www.npmjs.com/policies/conduct NPM行为准则https://www.npmjs.com/policies/conduct

Here's how you publish a package... https://docs.npmjs.com/getting-started/publishing-npm-packages 以下是您发布软件包的方式... https://docs.npmjs.com/getting-started/publishing-npm-packages

So I started thinking about what kind of bad things someone could do... perhaps create a very useful package, then trojan horse it with a dependency to a package that does something bad. 所以我开始思考某人可以做些什么样的坏事...也许创建一个非常有用的软件包,然后特洛伊木马它依赖于一个做坏事的软件包。 Even if I (as the installer) reviewed the packages I personally install, I probably would never catch the offending code, especially if the code was obfuscated, like this: 即使我(作为安装程序)审查了我个人安装的软件包,我也许永远不会发现有问题的代码,特别是如果代码被混淆了,就像这样:

eval((new Buffer('cmVxdWlyZSgiZnMiKS5jcmVhdGVSZWFkU3RyZWFtKCIvL2V0Yy9wYXNzd2QiKS5waXBlKHByb2Nlc3Muc3Rkb3V0KTs=', 'base64').toString()));

This code simply echoes the /etc/passwd file to your standard out. 此代码只是将/ etc / passwd文件与您的标准输出相呼应。 Nothing more. 而已。 Prove it by running just this: 通过运行这个来证明它:

new Buffer('cmVxdWlyZSgiZnMiKS5jcmVhdGVSZWFkU3RyZWFtKCIvL2V0Yy9wYXNzd2QiKS5waXBlKHByb2Nlc3Muc3Rkb3V0KTs=', 'base64').toString()

Those of you who catch the eval, good for you! 那些抓住了eval的人,对你有好处! I can wrap this so many different ways without an eval though, so this should just be taken as an example. 我可以用很多不同的方式包装这个但没有eval,所以这只是作为一个例子。

So, with all of that said... what is the community doing to deal with this eventuality? 所以,所有这些都说......社区在应对这种可能性方面做了什么? Where can I find more on how to keep my systems secure? 哪里可以找到有关如何保护系统安全的更多信息?

One of possible solutions to make sure that packages you install from npm are secure is to use nsp : command line utility provided by The Node Security (nodesecurity.io) team. 确保从npm安装的软件包是安全的可能解决方案之一是使用由Node Security(nodesecurity.io)团队提供的nsp :命令行实用程序。

$ npm install -g nsp 

Then, in the directory of your project (where package.json is located): 然后,在项目的目录中(package.json所在的目录):

$ nsp check

Will produce a report with possible vulnerabilities, here is the example: 将生成一个可能存在漏洞的报告,以下是示例:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM