Mitigating Malware in the Python Ecosystem with Chainguard Libraries

Mitigating malware in the python ecosystem with Chainguard Libraries

Aaditya Jain
Senior Product Marketing Manager
Chainguard

Stop installing risk from PyPI

Malware attacks in the Python ecosystem are growing in severity and frequency, with many tainted packages appearing on the Python Package Index (PyPI) each year. To mitigate malware in open source libraries, Chainguard recently announced Chainguard Libraries for Python, a malware-resistant index of packages in which each library and its full dependency tree is built from source inside our hardened infrastructure.

To verify our malware-mitigation thesis, we analyzed ~3,025 malicious Python packages sourced from the Backstabber’s Knife Collection, which has grown considerably since its initial release and is now considered one of the most well-vetted datasets of known malicious open source libraries.

Our results found that by requiring an attributable source and validating source-to-artifact integrity, Chainguard Libraries would have prevented ~98% of those malicious packages from being published.

The main reason is that a majority of these malicious libraries (~92%) do not have attributable source code URLs – which we consider the true source code. Instead, these wheel packages have fake code bundled into the source distribution (sdist), and understandably do not make their malicious code available anywhere. Since Chainguard goes straight to the raw Python source code from a public repository such as GitHub, the Chainguard Factory would not have built and distributed these libraries. No such public source code exists for the malware. If we strip out these malicious packages that lack source code, our analysis shows that users would have mitigated 75% of malware.

In the rest of this post, we’ll walk through our research approach and methodology, highlight the key findings, and close with practical takeaways for security leaders.

Methodology and Results

For this analysis, Chainguard leveraged the ~3,000 known malicious packages from the Backstabber’s Knife Collection, a dataset of known open source package malware. We then created a simple decision tree to determine whether or not Chainguard Libraries would have mitigated each individual malicious dependency. A critical assumption we make in this analysis is that Chainguard Libraries is treated as the primary source for language dependencies, with no fall back to PyPI, where many of these malicious packages originated.

Below is the full dependency tree, with three key stages and results:

Key Takeaways for Security Teams

Malware in the Python ecosystem is running rampant. Relying on public repositories that are oriented for ease of publisher convenience as opposed to enterprise security presents a significant risk. The most effective way for security teams to combat malware is by turning to secure and trusted open source libraries that have been built entirely from source in hardened infrastructure. This is the approach that Chainguard Libraries is taking at its core, and one that shows promising results in mitigating malware at its roots based on our analysis.

If you’d like to learn more about how Chainguard Libraries can transform your software supply chain, reach out today.