The npm ecosystem is open by design, allowing arbitrary users to freely share and reuse code. Reusing a package is as simple as invoking a single command, which will download and install the package and all its transitive dependencies. Sharing a package with the community is similarly easy, making code available to all others without any restrictions or checks. The openness of npm has enabled its growth, providing packages for any situation imaginable, ranging from small utility packages to complex web server frameworks and user interface libraries.
Perhaps unsurprisingly, npm’s openness comes with security risks, as evidenced by several recent incidents that broke or attacked software running on millions of computers. In March 2016, the removal of a small utility package called left-pad
Are these incidents unfortunate individual cases or first evidence of a more general problem? Given the popularity of npm, better understanding its weak points is an important step toward securing this software ecosystem. In this paper, we systematically study security risks in the npm ecosystem by analyzing package dependencies, maintainers of packages, and publicly reported security issues. In particular, we study the potential of individual packages and maintainers to impact the security of large parts of the ecosystem, as well as the ability of the ecosystem to handle security issues. Our analysis is based on a set of metrics defined on the package dependency graph and its evolution over time. Overall, our study involves 5,386,239 versions of packages, 199,327 maintainers, and 609 publicly known security issues.
The overall finding is that the densely connected nature of the npm ecosystem introduces several weak spots. Specifically, our results include:
Installing an average npm package introduces an implicit trust on 79 third-party packages and 39 maintainers, creating a surprisingly large attack surface.
Highly popular packages directly or indirectly influence many other packages (often more than 100,000) and are thus potential targets for injecting malware.
Some maintainers have an impact on hundreds of thousands of packages. As a result, a very small number of compromised maintainer accounts suffices to inject malware into the majority of all packages.
The influence of individual packages and maintainers has been continuously growing over the past few years, aggravating the risk of malware injection attacks.
A significant percentage (up to 40%) of all packages depend on code with at least one publicly known vulnerability.
Overall, these findings are a call-to-arms for mitigating security risks on the npm ecosystem. As a first step, we discuss several mitigation strategies and analyze their potential effectiveness. One strategy would be a vetting process that yields trusted maintainers. We show that about 140 of such maintainers (out of a total of more than 150,000) could halve the risk imposed by compromised maintainers. Another strategy we discuss is to vet the code of new releases of certain packages. We show that this strategy reduces the security risk slightly slower than trusting the involved maintainers, but it still scales reasonably well, i.e., trusting the top 300 packages reduces the risk by half. If a given package passes the vetting process for maintainers and code, we say it has “perfect first-party security”. If all its transitive dependencies pass the vetting processes we say that it has “perfect third-party security”. If both conditions are met, we consider it a “fully secured package”. While achieving this property for all the packages in the ecosystem is infeasible, packages that are very often downloaded or that have several dependents should aim to achieve it.
2 Security Risks in the npm Ecosystem
To set the stage for our study, we describe some security-relevant particularities of the npm ecosystem and introduce several threat models.
2.1 Particularities of npm
In npm, dependencies are declared in a configuration file called package.json, which specifies the name of the dependent package and a version constraint. The version constraint either gives a specific version, i.e., the dependency is locked, or specifies a range of compatible versions, e.g., newer than version X. Each time an npm package is installed, all its dependencies are resolved to a specific version, which is automatically downloaded and installed.
Therefore, the same package installed on two different machines or at two different times may download different versions of a dependency. To solve this problem, npm introduced package-lock.json, which developers can use to lock their transitive dependencies to a specific version until a new lock file is generated. That is, each package in the dependency tree is locked to a specific version. In this way, users ensure uniform installation of their packages and coarse grained update of their dependencies. However, a major shortcoming of this approach is that if a vulnerability is fixed for a given dependency, the patched version is not installed until the package-lock.json file is regenerated. In other words, developers have a choice between uniform distribution of their code and up-to-date dependencies. Often they choose the later, which leads to a technical lag between the latest available version of a package and the one used by dependents.
Recent work [18, 11] provides preliminary evidence that code reuse in npm differs significantly from other ecosystems. One of the main characteristic of the npm ecosystem is the high number of transitive dependencies. For example, when using the core of the popular Spring web framework in Java, a developer transitively depends on ten other packages. In contrast, the Express.js web framework transitively depends on 47 other packages.
Related to the reuse culture, another interesting characteristic of npm is the heavy reliance on packages that consist of only few lines of source code, which we call micropackages. Related work documents this trend and warns about its dangers [1, 19]. These packages are an important part of the ecosystem, yet they increase the surface for certain attacks as much as functionality heavy packages. This excessive fragmentation of the npm codebase can thus lead to very high number of dependencies.
No Privilege Separation
No Systematic Vetting
The process of discovering vulnerabilities in npm packages is still in its infancy. There currently is no systematic vetting process for code published on npm. Instead, known vulnerabilities are mostly reported by individuals, who find them through manual analysis or in recent research work, e.g., injection vulnerabilities , regular expression denial of service [9, 29], path traversals , binding layer bugs .
In order to publish a package, a developer needs to first create an account on the npm website. Once this prerequisite is met, adding a new package to the repository is as simple as running the “npm publish” command in a folder containing a package.json file. The user who first published the package is automatically added to the maintainers set and hence she can release future versions of that package. She can also decide to add additional npm users as maintainers. What is interesting to notice about this model is that it does not require a link to a public version control system, e.g., GitHub, hosting the code of the package. Nor does it require that persons who develop the code on such external repositories also have publishing rights on npm. This disconnect between the two platforms has led to confusion444http://www.cs.tufts.edu/comp/116/archive/spring2018/etolhurst.pdf in the past and to stealthy attacks that target npm accounts without changes to the versioning system.
2.2 Threat Models
The idiosyncratic security properties of npm, as described above, enable several scenarios for attacking users of npm packages. The following discusses threat models that either correspond to attacks that have already occurred or that we consider to be possible in the future.
Malicious Packages (TM-mal)
Adversaries may publish packages containing malicious code on npm and hence trick other users into installing or depending on such packages. In 2018, the eslint-scope incident mentioned earlier has been an example of this threat. The package deployed its payload at installation time through an automatically executed post-installation script. Other, perhaps more stealthy methods for hiding the malicious behavior could be envisioned, such as downloading and executing payloads only at runtime under certain conditions.
Strongly related to malicious packages are packages that violate the user’s privacy by sending usage data to third parties, e.g., insight555https://www.npmjs.com/package/insight or analytics-node666https://www.npmjs.com/package/analytics-node. While these libraries are legitimate under specific conditions, some users may not want to be tracked in this way. Even though the creators of these packages clearly document the tracking functionality, transitive dependents may not be aware that one of their dependencies deploys tracking code.
Exploiting Unmaintained Legacy Code (TM-leg)
As with any larger code base, npm contains vulnerable code, some of which is documented in public vulnerability databases such as npm security advisories777https://www.npmjs.com/advisories or Snyk vulnerability DB888https://snyk.io/vuln/?type=npm. As long as a vulnerable package remains unfixed, an attacker can exploit it in applications that transitively depend on the vulnerable code. Because packages may become abandoned due to developers inactivity  and because npm does not offer a forking mechanism, some packages may never be fixed. Even worse, the common practice of locking dependencies may prevent applications from using fixed versions even when they are available.
Package Takeover (TM-pkg)
An adversary may convince the current maintainers of a package to add her as a maintainer. For example, in the recent event-stream incident999https://github.com/dominictarr/event-stream/issues/116, the attacker employed social engineering to obtain publishing rights on the target package. The attacker then removed the original maintainer and hence became the sole owner of the package. A variant of this attack is when an attacker injects code into the source base of the target package. For example, such code injection may happen through a pull request, via compromised development tools, or even due to the fact that the attacker has commit rights on the repository of the package, but not npm publishing rights. Once vulnerable or malicious code is injected, the legitimate maintainer would publish the package on npm, unaware of its security problems. Another takeover-like attack is typosquatting, where an adversary publishes malicious code under a package name similar to the name of a legitimate, popular package. Whenever a user accidentally mistypes a package name during installation, or a developer mistypes the name of a package to depend on, the malicious code will be installed. Previous work shows that typosquatting attacks are easy to deploy and effective in practice .
Account Takeover (TM-acc)
The security of a package depends on the security of its maintainer accounts. An attacker may compromise the credentials of a maintainer to deploy insecure code under the maintainer’s name. At least one recent incident (eslint-scope) is based on account takeover. While we are not aware of how the account was hijacked in this case, there are various paths toward account takeover, e.g., weak passwords, social engineering, reuse of compromised passwords, and data breaches on npm.
Collusion Attack (TM-coll)
The above scenarios all assume a single point of failure. In addition, the npm ecosystem may get attacked via multiple instances of the above threats. Such a collusion attack may happen when multiple maintainers decide to conspire and to cause intentional harm, or when multiple packages or maintainers are taken over by an attacker.
To analyze how realistic the above threats are, we systematically study package dependencies, maintainers, and known security vulnerabilities in npm. The following explains the data and metrics we use for this study.
3.1 Data Used for the Study
Packages and Their Dependencies
To understand the impact of security problems across the ecosystem, we analyze the dependencies between packages and their evolution.
Let be a specific point in time, be a set of npm package names, and a set of directed edges between packages, where has a regular dependency on . We call the npm dependency graph at a given time .
We denote the universe of all packages ever published on npm with . By aggregating the meta information about packages, we can easily construct the dependency graph without the need to download or install every package. Npm offers an API endpoint for downloading this metadata for all the releases of all packages ever published. In total we consider 676,539 nodes and 4,543,473 edges.
To analyze the evolution of packages we gather data about all their releases. As a convention, for any time interval , such as years or months, we denote with the snapshot at the beginning of that time interval. For example, refers to the dependency graph at the beginning of the year 2015. In total we analyze 5,386,239 releases, therefore an average of almost eight versions per package. Our observation period ends in April 2018.
Every package has one or more developers responsible for publishing updates to the package.
For every , the set of maintainers contains all users that have publishing rights for .
Note that a specific user may appear as the maintainer of multiple packages and that the union of all maintainers in the ecosystem is denoted with .
The npm community issues advisories or public reports about vulnerabilities in specific npm packages. These advisories specify if there is a patch available and which releases of the package are affected by the vulnerability.
We say that a given package is
vulnerable at a moment if there exists a public
advisory for that package and if no patch was released for the described
vulnerability at an earlier moment
if there exists a public advisory for that package and if no patch was released for the described vulnerability at an earlier moment.
We denote the set of vulnerable packages with . In total, we consider 609 advisories affecting 600 packages. We extract the data from the publicly available npm advisories101010https://www.npmjs.com/advisories.
We introduce a set of metrics for studying the risk of attacks on the npm ecosystem.
Packages and Their Dependencies
The following measures the influence of a given package on other packages in the ecosystem.
For every , the package reach represents the set of all the packages that have a transitive dependency on in .
Note that the package itself is not included in this set. The reach contains names of packages in the ecosystem. Therefore, the size of the set is bounded by the following values .
Since does not account for the ecosystem changes, the metric may grow simply because the ecosystem grows. To address this, we also consider the average package reach:
Using the bounds discussed before for , we can calculate the ones for its average . The upper limit is obtained for a fully connected graph in which all packages can reach all the other packages and hence . If grows monotonously, we say that the ecosystem is getting more dense, and hence the average package influences an increasingly large number of packages.
The inverse of package reach is a metric to quantify how many packages are implicitly trusted when installing a particular package.
For every , the set of implicitly trusted packages contains all the packages for which .
Similarly to the previous case, we also consider the size of the set and the average number of implicitly trusted package , having the same bounds as their package reach counterpart.
Even though the average metrics and are equivalent for a given graph, the distinction between their non-averaged counterparts is very important from a security point of view. To see why, consider the example in Figure 1. The average is 5/6 = 0.83 both on the right and on the left. However, on the left, a popular package is dependent upon by many others. Hence, the package reach of is five, and the number of implicitly trusted packages is one for each of the other packages. On the right, though, the number of implicitly trusted packages for is three, as users of implicitly trust packages , , and .
The number of implicitly trusted packages or the package reach are important metrics for reasoning about TM-pkg, but not about TM-acc. That is because users may decide to split their functionality across multiple micropackages for which they are the sole maintainers. To put it differently, a large attack surface for TM-pkg does not imply one for TM-acc.
Therefore, we define maintainer reach and implicitly trusted maintainers for showing the influence of maintainers.
Let be an npm maintainer. The maintainer reach is the combined reach of all the maintainer’s packages,
For every , the set of implicitly trusted maintainers contains all the maintainers that have publishing rights on at least one implicitly trusted package, .
The above metrics have the same bounds as their packages counterparts. Once again, the distinction between the package and the maintainer-level metrics is for shedding light on the security relevance of human actors in the ecosystem.
Furthermore, to approximate the maximum damage that colluding maintainers can incur on the ecosystem (TM-coll), we define an order in which the colluding maintainers are selected:
We call an ordered set of maintainers a desirable collusion strategy iff there is no for which .
Therefore, the desirable collusion strategy is a hill climbing algorithm in which at each step we choose the maintainer that provides the highest local increase in package reach at that point. We note that the problem of finding the set of maintainers that cover the most packages is an NP-hard problem called maximum coverage problem. Hence, we believe that the proposed solution is a good enough approximation that shows how vulnerable the ecosystem is to a collusion attack, but that does not necessary yield the optimal solution.
For reasoning about TM-leg, we need to estimate how much of the ecosystem depends on vulnerable code:
Given all vulnerable packages at time , we define the reach of vulnerable code at time as .
Of course the actual reach of vulnerable code can not be fully calculated since it would rely on all vulnerabilities present in npm modules, not only on the published ones. However, since in TM-leg we are interested in publicly known vulnerabilities, we define our metric according to this scenario. In these conditions, the speed at which vulnerabilities are reported is an important factor to consider:
Given all vulnerable packages at time , we define the vulnerability reporting rate at time as .
We start by reporting the results on the nature of package level dependencies and their evolution over time (corresponding to TM-mal and TM-pkg). We then discuss the influence that maintainers have in the ecosystem (related to TM-acc and TM-coll). Finally, we explore the dangers of depending on unpatched security vulnerabilities (addressing TM-leg).
4.1 Dependencies in the Ecosystem
To set the stage for a thorough analysis of security risks entailed by the structure of the npm ecosystem, we start with a general analysis of npm and its evolution. Since its inception in 2010, the npm ecosystem has grown from a small collection of packages maintained by a few people to the world’s largest software ecosystem. Figure 2 shows the evolution of the number of packages available on npm and the number of maintainers responsible for these packages. Both numbers have been increasing super-linearly over the past eight years. At the end of our measurement range, there is a total of 676,539 packages, a number likely to exceed one million in the near future. These packages are taken care of by a total of 199,327 maintainers. The ratio of packages to maintainers is stable across our observation period (ranging between 2.81 and 3.51).
4.1.1 Direct and Transitive Dependencies
Figure 3 shows how many other packages an average npm package depends on directly and transitively. The number of direct dependencies has been increasing slightly from 1.3 in 2011 to 2.8 in 2018, which is perhaps unsurprising given the availability of an increasing code base to reuse. The less obvious observation is that a small, linear increase in direct dependencies leads to a significant, super-linear increase in transitive dependencies. As shown by the upper line in Figure 3, the number of transitive dependencies of an average package has increased to a staggering 80 in 2018 (note the logarithmic scale).
From a security perspective, it is important to note that each directly or transitively depended on package becomes part of the implicitly trusted code base. When installing a package, each depended upon package runs its post-installation scripts on the user’s machine – code executed with the user’s operating system-level permissions. When using the package, calls into third-party modules may execute any of the code shipped with the depended upon packages.
One can observe in Figure 3 a chilling effect on the number of dependencies around the year 2016 which will become more apparent in the following graphs. Decan et al.  hypothesize that this effect is due to the left-pad incident. In order to confirm that this is not simply due to removal of more than a hundred packages belonging to the left-pad’s owner, we remove all the packages owned by this maintainer. We see no significant difference for the trend in Figure 3 when removing these packages, hence we conclude that indeed there is a significant change in the structure of transitive dependencies in the ecosystem around 2016.
4.1.2 Package Reach
The above analysis focuses on depended upon packages. We now study the inverse phenomenon: packages impacted by individual packages, i.e., package reach as defined in Section 3. Figure 4 shows how many other packages a single package reaches via direct or indirect dependencies. The graph at the top is for an average package, showing that it impacts about 230 other packages in 2018, a number that has been growing since the creation of npm. The graph at the bottom shows the package reach of the top-5 packages (top in terms of their package reach, as of 2018). In 2018, these packages each reach between 134,774 and 166,086 other packages, making them an extremely attractive target for attackers.
To better understand how the reach of packages evolves over time, Figure 5 shows the distribution of reached packages for multiple years. For example, the red line shows that in 2018, about 24,500 packages have reached at least 10 other packages, whereas only about 9,500 packages were so influential in 2015. Overall, the figure shows that more and more packages are reaching a significant number of other packages, increasing the attractiveness of attacks that rely on dependencies.
The high reach of a package amplifies the effect of both vulnerabilities (TM-leg) and of malicious code (TM-mal). As an example for the latter, consider the event-stream incident discussed when introducing TM-acc in Section 2.2. By computing event-stream’s reach and comparing it with other packages, we see that this package is just one of many possible targets. As of April 1, 2018 (the end of our measurement period), event-stream has a reach of 5,466. That is, the targeted package is relatively popular, but still far from being the top-most attractive package to compromise. In fact, 1,165 other packages have a greater or equal reach than event-stream.
In order to perform a similar analysis for the eslint-scope security incident, we need to use a slightly modified version of package reach. This attack targeted a development tool, namely eslint, hence, to fully estimate the attack surface we need to consider dev dependencies in our definition of reach. We do not normally consider this type of dependencies in our measurements because they are not automatically installed with a package, unlike regular dependencies. They are instead used only by the developers of the packages. Therefore the modified version of package reach considers both transitive regular dependencies and direct dev dependencies.
We observe that eslint-scope has a modified reach of more than 100,000 packages at the last observation point in the data set. However, there are 347 other packages that have a higher reach, showing that even more serious attacks may occur in the future.
4.2 Analysis of Maintainers
We remind the reader that there is a significant difference between npm maintainers and repository contributors, as discussed in Section 2.1. Even though contributors also have a lot of control over the code that will eventually end up in an npm package, they can not release a new version on npm, only the maintainers have this capability. Hence, the discussion that follows, about the security risks associated with maintainers, should be considered a lower bound for the overall attack surface.
Attacks corresponding to TM-acc in which maintainers are targeted are not purely hypothetical as the infamous eslint-scope incident discussed earlier shows. In this attack, a malicious actor hijacked the account of an influential maintainer and then published a version of eslint-scope containing malicious code. This incident is a warning for how vulnerable the ecosystem is to targeted attacks and how maintainers influence can be used to deploy malware at scale. We further discuss the relation between packages and maintainers.
4.2.1 Packages per Maintainer
Even though the ecosystem grows super-linearly as discussed in Section 4.1, one would expect that this is caused mainly by new developers joining the ecosystem. However, we observe that the number of packages per maintainer also grows suggesting that the current members of the platform are actively publishing new packages. The average number of packages controlled by a maintainer raises from 2.5 in 2012 to 3.5 in 2013 and almost 4.5 in 2018. Conversely, there are on average 1.35 maintainers in the lifetime of a package. The top 5,000 most popular packages have an average number of 2.83 maintainers. This is not unexpected, since multiple people are involved in developing the most popular packages, while for the majority of new packages there is only one developer.
Next, we study in more detail the evolution of the number of packages a maintainer controls. Figure 6 shows the maintainer package count plotted versus the number of maintainers having such a package count. Every line represents a year. The scale is logarithmic to base 10. It shows that the majority of maintainers maintain few packages, yet some maintainers maintain over 100 packages. Over the years, the package count for the maintainers increased consistently. In 2015, only slightly more than 25,000 maintainers maintained more than one package, whereas this number has more than tripled by 2018.
We further analyze five different maintainers in top 20 according to number of packages and plot the evolution of their package count over the years in Figure 7. types is the largest maintainer of type definitions for TypeScript, most likely a username shared by multiple developers at Microsoft, ehsalazar maintains many security placeholder packages, jonschlinkert and sindresorhus are maintaining many micropackages and isaacs is the npm founder. From Figure 7 we can see that for two of these maintainers the increase is superlinear or even near exponential: types and kylemathews have sudden spikes where they added many packages in a short time. We explain this by the tremendous increase in popularity for TypeScript in the recent years and by the community effort to prevent typosquatting attacks by reserving multiple placeholder. The graph of the other maintainers is more linear, but surprisingly it shows a continuous growth for all the six maintainers.
4.2.2 Implicitly Trusted Maintainers
One may argue that the fact that maintainers publish new packages is a sign of a healthy ecosystem and that it only mimics its overall growth. However, we show that while that may be true, we also see an increase in the general influence of maintainers. That is, on average every package tends to transitively rely on more and more maintainers over time.
In Figure 8 we show the evolution of , the average number of implicitly trusted maintainers. As can be seen, almost doubled in the last three years for the average npm package, despite the plateau of the curve reached in 2016 which we again speculate it is caused by the left-pad incident. This is a worrisome development since compromising any of the maintainer accounts a package trusts may seriously impact the security of that package, as discussed in TM-acc. The positive aspect of the data in Figure 8 is that the growth in the number of implicitly trusted maintainers seems to be less steep for the top 10,000 packages compared to the whole ecosystem. We hypothesize that the developers of popular packages are aware of this problem and actively try to limit the . However, a value over 20 for the average popular package is still high enough to be problematic.
When breaking the average discussed earlier into individual points in Figure 9, one can observe that the majority of these packages can be influenced by more than one maintainer. This is surprising since most of the popular packages are micropackages such as "inherits" or "left-pad" or libraries with no dependencies like "moment" or "lodash". However, only around 30% of these top packages have a maintainer cost higher than 10. Out of these, though, there are 643 packages influenced by more than a hundred maintainers.
4.2.3 Maintainers Reach
In Figure 10, we plot the reach of the maintainers in the npm ecosystem. The reach has increased over the years at all levels. For example, in 2015 there were 2,152 maintainers that could affect more than 10 packages, and this number increased to 4,041 in 2016, 6,680 in 2017 and finally reaching an astonishingly high 10,534 in 2018. At the other end of the distribution, there were 59 maintainers that could affect more than 10,000 packages in 2015, 163 in 2016, 249 in 2017 and finally 391 in 2018. The speed of growth for is worrisome, showing that more and more developers have control over thousands of packages. If an attacker manages to compromise the account of any of the 391 most influential maintainers, the community will experience a serious security incident, reaching twice as many packages as in the event-stream attack.391 highly influential maintainers affect more than 10,000 packages, making them prime targets for attacks.
The problem has been aggravating over the past years.
Finally, we look at the scenario in which multiple popular maintainers collude, according to the desirable collusion strategy introduced in Section 3.2, to perform a large-scale attack on the ecosystem, i.e., TM-col. In Figure 11 we show that 20 maintainers can reach more than half of the ecosystem. Past that point every new maintainer joining does not increase significantly the attack’s performance.
4.3 Security Advisories Evolution
Next, we study how often vulnerabilities are reported and fixed in the npm ecosystem (TM-leg). Figure 12 shows the number of reported vulnerabilities in the lifetime of the ecosystem. The curve seems to resemble the evolution of number of packages presented in Figure 2, with a steep increase in the last two years. To explore this relation further we plot in Figure 13 the evolution of the number of advisories reported per 10,000 packages and we observe that it grows from two in 2013 to almost eight in 2018. This is a sign of a healthy security community that reports vulnerabilities at a very good pace, keeping up with the growth of the ecosystem.
When analyzing the type of reported vulnerabilities in details, we observe that almost half of the advisories come from two large-scale campaigns and not a broader community effort: First, there are 141 advisories published in January 2017 involving npm packages that download resources over HTTP, instead of HTTPs. Second, there are 120 directory traversal vulnerabilities reported as part of the research efforts of Liang Gong . Nevertheless, this shows the feasibility of large-scale vulnerability detection and reporting on npm.
Publishing an advisory helps raise awareness of a security problem in an npm package, but in order to keep the users secure, there needs to be a patch available for a given advisory. In Figure 12 we show the evolution of the number of unpatched security vulnerabilities in npm, as defined in Section 3. This trend is alarming, suggesting that two out of three advisories are still unpatched, leaving the users at risk. When manually inspecting some of the unpatched advisories we notice that a large percentage of unpatched vulnerabilities are actually advisories against malicious typosquatting packages for which no fix can be available.
To better understand the real impact of the unpatched vulnerabilities we analyze how much of the ecosystem they impact, i.e., vulnerability reach as introduced in Section 3.2. To that end, we compute the reach of unpatched packages at every point in time in Figure 14. At a first sight, this data shows a much less grim picture than expected, suggesting that the reach of vulnerable packages is dropping over time. However, we notice that the effect of vulnerabilities tends to be retroactive. That is, a vulnerability published in 2015 affects multiple versions of a package released prior to that date, hence influencing the data points corresponding to the years 2011-2014 in Figure 14. Therefore, the vulnerabilities that will be reported in the next couple of years may correct for the downwards trend we see on the graph. Independent of the downwards trend, the fact that for the majority of the time the reach of vulnerable unpatched code is between 30% and 40% is alarming.
One initial defense against the attacks described in this paper is to make users more aware of the quality of the code they depend on. Currently, for a given package, npm shows the number of downloads, dependencies, dependents and open issues on the associated repositories. However, they do not show any information about the transitive dependencies or about the number of maintainers that can influence a given package. We believe that including such information can help users better understand the security risks associated with a given package and possibly encourage them to inspect the code of their transitive dependencies.
Inspecting every line of code of every dependency does not scale for most of the real-world projects. Therefore, new tools for security auditing code on npm are needed. Recently, there were several efforts for improving this state, both from academia, e.g., Synode , BreakApp , NodeSec , NoRegrets , Node.cure  and from industry practitioners, e.g., Semmle111111https://semmle.com/ and R2C121212https://returntocorp.com/, DeepScan131313https://deepscan.io/.
Moreover, in the last years, npm introduced several improvements to their vulnerability reporting and checking processes. First, a transparent HackerOne-based141414https://hackerone.com/nodejs-ecosystem workflow was introduced to encourage vulnerability reporters and maintainers to work together in a supervised way towards disclosing and patching security vulnerabilities. However, the community should be encouraged to report more security problems, possibly by recompensing top reporters with bug bounties. Second, npm audit was introduced to help upgrade direct dependencies that contain known vulnerabilities, but transitive dependencies on vulnerable modules are still a problem. Npm audit mostly relies on known vulnerabilities, hence its performance is dependent on how fast advisories are published. More worrisome, though, is the fact that this defense is insufficient against a malware attack. That is, npm audit is a slow, reactive defense that is unable to quickly stop the malware distribution. In the previous incidents involving malware, once the attack was detected, npm deleted from their database the malicious release altogether or even the entire package to avoid further infections.
Npm should adopt more proactive defenses and thus ensure that the malicious code does not get published in the ecosystem to begin with. The first such defense we propose is vetting the most influential maintainers. For example, the vetting process could validate the identity of maintainers, support maintainers in understanding basic security principles, and ensure that their accounts are protected by state-of-the-art techniques, such as two-factor authentication. Each maintainer that passes the vetting process is considered a trusted maintainer. However, it is not clear if this solution would scale to the more than 150,000 maintainers on npm today. To address this issue we look into how many maintainers must be trusted in order to drag the average number of implicitly trusted maintainers down to a reasonable level. That is, if a maintainer is trusted she is not included anymore in the computation of the . In Figure 15, the trust maintainers curve shows the evolution of the of the ecosystem as the set of trusted maintainers is growing. One needs to trust almost 140 maintainers in order to cut the in half and more than 600 to bring it below five. These results show that this mechanism scales reasonably well, but that hundreds of maintainers need to be vetted in order to bring the average number of implicitly trusted maintainers to a reasonable level.
In Figure 15 we also show an alternative defense strategy in which instead of vetting certain maintainers, npm can vet packages. That is, similarly to ecosystems such as AppStore, whenever a new release of a vetted package is published, certain code analyses are triggered for its code. If and only if the analyses validate the code, it is made available to the users. We say that a package that passes such checks is a trusted package. Since the vetting process may involve semi-automatic or even manual steps, we believe that it is realistic to assume that it will be deployed step by step in the ecosystem, starting with the most popular packages. In Figure 15, the trust packages curve shows that this defense scales comparably well with the maintainers one discussed earlier. Therefore, vetting the most dependent 1,500 packages would reduce the average number of implicitly trusted packages ten fold and trusting 4,000 packages would reduce it 25 times.
Once a mechanism for trusting packages or maintainers is in place, we can define a fully secured package as a package and maintainer that are trusted (perfect first-party security) and that transitively depends only on trusted maintainers or packages (perfect third-party security). We also propose using a continuous function that approximates how far a given package is from becoming a fully secured package. That is, whether the package’s maintainer and code are trusted, and the percentage of trusted maintainers or packages in all the transitive dependencies, can be displayed in the npm website as a security score for a package.
Finally, npm advocates the deployment of public key certificates for protecting the maintainers’ accounts. However, to the best of our knowledge, this solution is not yet adopted at scale and thus there are still several accounts at risk. We advocate our trusted maintainers model discussed earlier for reasoning about the adoption of public keys. That is, if a maintainer configures a public key for her account then she is considered trusted and thus safe against account hijacking. In this way, one may estimate how much of the ecosystem is at risk of account takeover due to lack of certificates.
6 Related Work
Studies of Software Ecosystems
where they use cluster analysis to explore different categories of software. German et al. study the dependency network of the R language and the community around its user-contributed packages. Bavota et al.  analyze the large Apache ecosystem of Java libraries where they find that while the number of projects grows linearly, the number of dependencies between them grows exponentially. Comparing this to the npm ecosystem, we find the number of packages to grow super-linearly while the average number of dependencies between them grows linearly.
We present a large-scale study of security threats resulting from the densely connected structure of npm packages and maintainers. The overall conclusion is that npm is a small world with high risks. It is “small” in the sense that packages are densely connected via dependencies. The security risk are “high” in the sense that vulnerable or malicious code in a single package may affect thousands of others, and that a single misbehaving maintainer, e.g., due to a compromised account, may have a huge negative impact. These findings show that recent security incidents in the npm ecosystem are likely to be the first signs of a larger problem, and not only unfortunate individual cases. To mitigate the risks imposed by the current situation, we analyze the potential effectiveness of several mitigation strategies. We find that trusted maintainers and a code vetting process for selected packages could significantly reduce current risks.
Acknowledgments This work was supported by the German Federal Ministry of Education and Research and by the Hessian Ministry of Science and the Arts within CRISP, by the German Research Foundation within the ConcSys and Perf4JS projects, and by the Hessian LOEWE initiative within the Software-Factory 4.0 project.
-  Rabe Abdalkareem, Olivier Nourry, Sultan Wehaibi, Suhaib Mujahid, and Emad Shihab. Why do developers use trivial packages? an empirical case study on npm. In FSE, 2017.
-  Rabe Abdalkareem, Olivier Nourry, Sultan Wehaibi, Suhaib Mujahid, and Emad Shihab. Why do developers use trivial packages? an empirical case study on npm. In Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering, ESEC/FSE 2017, Paderborn, Germany, September 4-8, 2017, pages 385–395, 2017.
-  Gabriele Bavota, Gerardo Canfora, Massimiliano Di Penta, Rocco Oliveto, and Sebastiano Panichella. The evolution of project inter-dependencies in a software ecosystem: The case of apache. In 2013 IEEE International Conference on Software Maintenance, Eindhoven, The Netherlands, September 22-28, 2013, pages 280–289, 2013.
-  Remco Bloemen, Chintan Amrit, Stefan Kuhlmann, and Gonzalo Ordóñez-Matamoros. Gentoo package dependencies over time. In 11th Working Conference on Mining Software Repositories, MSR 2014, Proceedings, May 31 - June 1, 2014, Hyderabad, India, pages 404–407, 2014.
-  Christopher Bogart, Christian Kästner, James D. Herbsleb, and Ferdian Thung. How to break an API: cost negotiation and community values in three software ecosystems. In Proceedings of the 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, FSE 2016, Seattle, WA, USA, November 13-18, 2016, pages 109–120, 2016.
-  Kyriakos C. Chatzidimitriou, Michail D. Papamichail, Themistoklis G. Diamantopoulos, Michail Tsapanos, and Andreas L. Symeonidis. npm-miner: an infrastructure for measuring the quality of the npm registry. In Proceedings of the 15th International Conference on Mining Software Repositories, MSR 2018, Gothenburg, Sweden, May 28-29, 2018, pages 42–45, 2018.
-  Eleni Constantinou and Tom Mens. An empirical comparison of developer retention in the rubygems and npm software ecosystems. ISSE, 13(2-3):101–115, 2017.
-  James C. Davis, Christy A. Coghlan, Francisco Servant, and Dongyoon Lee. The impact of regular expression denial of service (redos) in practice: an empirical study at the ecosystem scale. In Proceedings of the 2018 ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, ESEC/SIGSOFT FSE 2018, Lake Buena Vista, FL, USA, November 04-09, 2018, pages 246–256, 2018.
-  Alexandre Decan, Tom Mens, and Maëlick Claes. An empirical comparison of dependency issues in OSS packaging ecosystems. In IEEE 24th International Conference on Software Analysis, Evolution and Reengineering, SANER 2017, Klagenfurt, Austria, February 20-24, 2017, pages 2–12, 2017.
-  Alexandre Decan, Tom Mens, and Eleni Constantinou. On the evolution of technical lag in the npm package dependency network. In 2018 IEEE International Conference on Software Maintenance and Evolution, ICSME 2018, Madrid, Spain, September 23-29, 2018, pages 404–414, 2018.
-  Alexandre Decan, Tom Mens, and Eleni Constantinou. On the impact of security vulnerabilities in the npm package dependency network. In Proceedings of the 15th International Conference on Mining Software Repositories, MSR 2018, Gothenburg, Sweden, May 28-29, 2018, pages 181–191, 2018.
-  Alexandre Decan, Tom Mens, and Philippe Grosjean. An empirical comparison of dependency network evolution in seven software packaging ecosystems. CoRR, abs/1710.04936, 2017.
-  Daniel M. Germán, Bram Adams, and Ahmed E. Hassan. The evolution of the R software ecosystem. In 17th European Conference on Software Maintenance and Reengineering, CSMR 2013, Genova, Italy, March 5-8, 2013, pages 243–252, 2013.
-  Jaap Kabbedijk and Slinger Jansen. Steering insight: An exploration of the ruby software ecosystem. In Software Business - Second International Conference, ICSOB 2011, Brussels, Belgium, June 8-10, 2011. Proceedings, pages 44–55, 2011.
-  Riivo Kikas, Georgios Gousios, Marlon Dumas, and Dietmar Pfahl. Structure and evolution of package dependency networks. In Proceedings of the 14th International Conference on Mining Software Repositories, MSR 2017, Buenos Aires, Argentina, May 20-28, 2017, pages 102–112, 2017.
-  Timothy Libert. Exposing the hidden web: An analysis of third-party HTTP requests on 1 million websites. CoRR, abs/1511.00619, 2015.
-  Konstantinos Manikas. Revisiting software ecosystems research: A longitudinal literature study. Journal of Systems and Software, 117:84–103, 2016.
-  Tom Mens. An ecosystemic and socio-technical view on software maintenance and evolution. In 2016 IEEE International Conference on Software Maintenance and Evolution, ICSME 2016, Raleigh, NC, USA, October 2-7, 2016, pages 1–8, 2016.
-  Gianluca Mezzetti, Anders Møller, and Martin Toldam Torp. Type regression testing to detect breaking changes in node.js libraries. In 32nd European Conference on Object-Oriented Programming, ECOOP 2018, July 16-21, 2018, Amsterdam, The Netherlands, pages 7:1–7:24, 2018.
-  Brian Pfretzschner and Lotfi Ben Othmane. Identification of dependency-based attacks on node.js. In Proceedings of the 12th International Conference on Availability, Reliability and Security, Reggio Calabria, Italy, August 29 - September 01, 2017, pages 68:1–68:6, 2017.
-  Alexander Serebrenik and Tom Mens. Challenges in software ecosystems research. In Proceedings of the 2015 European Conference on Software Architecture Workshops, Dubrovnik/Cavtat, Croatia, September 7-11, 2015, pages 40:1–40:6, 2015.
-  Cristian-Alexandru Staicu, Michael Pradel, and Benjamin Livshits. SYNODE: understanding and automatically preventing injection attacks on NODE.JS. In 25th Annual Network and Distributed System Security Symposium, NDSS 2018, San Diego, California, USA, February 18-21, 2018, 2018.
-  Nikolai Philipp Tschacher. Typosquatting in programming language package managers. PhD thesis, Universität Hamburg, Fachbereich Informatik, 2016.
-  Nikos Vasilakis, Ben Karel, Nick Roessler, Nathan Dautenhahn, André DeHon, and Jonathan M. Smith. Breakapp: Automated, flexible application compartmentalization. In 25th Annual Network and Distributed System Security Symposium, NDSS 2018, San Diego, California, USA, February 18-21, 2018, 2018.
-  Jie Wang, Wensheng Dou, Yu Gao, Chushu Gao, Feng Qin, Kang Yin, and Jun Wei. A comprehensive study on real world concurrency bugs in node.js. In Proceedings of the 32nd IEEE/ACM International Conference on Automated Software Engineering, ASE 2017, Urbana, IL, USA, October 30 - November 03, 2017, pages 520–531, 2017.