Live data from Hacker News

A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

arxiv.org

11–20 of 28 posts

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#11
post #6

Earlier quoted context omitted.

Yes this, but also you shouldn't do an analysis like this on all of PyPi. Anyone can upload to it. It's full of abandoned experiments, name-squatting, and college students uploading hello world libraries just to learn how to do it. Analyzing those is pointless because nobody is using them and nobody is going to use them. Also listing the subprocess module as a standout because of code injection seems silly. That's th…

I was with you until you said that Python is largely intended for system administration automation. Python is used in a wide variety of application environments, especially the web. For example, early versions of Youtube were nothing more than a Python application. Many websites run Django, or other web frameworks. Python is heavily used in scientific computing environments, in data retrieval and visualization, as we…

> For example, early versions of Youtube were nothing more than a Python application

I heard about it, but I'm wondering, is that how Python got popular at Google and then become mainstream?

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#12
post #11
post #6

Earlier quoted context omitted.

I was with you until you said that Python is largely intended for system administration automation. Python is used in a wide variety of application environments, especially the web. For example, early versions of Youtube were nothing more than a Python application. Many websites run Django, or other web frameworks. Python is heavily used in scientific computing environments, in data retrieval and visualization, as we…

> For example, early versions of Youtube were nothing more than a Python application I heard about it, but I'm wondering, is that how Python got popular at Google and then become mainstream?

Python applications were widely used before either Google or YouTube existed

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#13
post #4

From the PDF, these are some of the security vulnerabilities that the static analysis came up with: Use of the exec function Insecure permissions for files Binding a socket to all network interfaces Use of hard-coded passwords in non-function contexts Use of hard-coded passwords in function arguments Use of hard-coded passwords in default function arguments Use of hard-coded temporary directories Using pass as a catc…

I agree most can be used securely, but I can't think of any legitimate use for DES in 2021. The old hash functions obviously have utility in non-secure contexts, but not really symmetric encryption.

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#14
post #4

From the PDF, these are some of the security vulnerabilities that the static analysis came up with: Use of the exec function Insecure permissions for files Binding a socket to all network interfaces Use of hard-coded passwords in non-function contexts Use of hard-coded passwords in function arguments Use of hard-coded passwords in default function arguments Use of hard-coded temporary directories Using pass as a catc…

I agree most can be used securely, but I can't think of any legitimate use for DES in 2021. The old hash functions obviously have utility in non-secure contexts, but not really symmetric encryption.

I can think of one specific use case: supporting an upgrade path for older versions of a given application.

That's about it though.

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#16
post #2

Their conclusion, "security issues are common in PyPI packages", doesn't really follow from the results. Their methods will classify any use of a function that is not cryptographically secure (MD5, random), even if it is not used in a cryptographic setting. Similarly any use of a function that is not safe to use on untrusted input (pickle, yaml.load, subprocess, eval) will be flagged, even if the usage is completely…

Yes this, but also you shouldn't do an analysis like this on all of PyPi. Anyone can upload to it. It's full of abandoned experiments, name-squatting, and college students uploading hello world libraries just to learn how to do it. Analyzing those is pointless because nobody is using them and nobody is going to use them. Also listing the subprocess module as a standout because of code injection seems silly. That's th…

It is possible to use subprocess safely, you just have to be aware of the sharp edges of it: shell=True, sanitising commands, option injection.

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#17
post #11

Earlier quoted context omitted.

> For example, early versions of Youtube were nothing more than a Python application I heard about it, but I'm wondering, is that how Python got popular at Google and then become mainstream?

Python applications were widely used before either Google or YouTube existed

Yes, but Python is actually older than Java, yet the boom started much later for Python.

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#18
This kind of research always interests me and at first glance I had a concern with this paper given that they mention:

> The dataset is based on a simple index file provided in the Python Package Index [76]. In total, 224,651 packages were listed in the index at the time of retrieving it.

For separate research reasons I've recently had cause to download the index as well and current versions are 315,000+ packages. The reference [76] indicates they retrieved it on March 28, 2020.

Initially I had thought that almost 100k packages in a little over a year had to be incorrect given that the first archived index from 2018 had around 170k packages listed (meaning 170k -> 225k in 2 years).

This increase probably just highlights just how much Python has just exploded in popularity. However, it does cast some doubt on the effectiveness of this kind of research on the basis that there are a lot of new packages and likely noise in that dataset.

A follow-up and perhaps more useful bit of research would be to do this same analysis with the top downloaded packages visible via the published stats[1] and then perform evaluations as to whether Bandit was actually identifying vulnerabilities. I have no doubt that of the 197,726 packages they actually scanned there was a lot of noise. Also, if a package has fewer than some cutoff of downloads in the past month (perhaps 10, 100?) or is newer than a certain date it may make sense to exclude it.

The authors mention the accuracy of static analysis tools being a potential problem but the fact that no spot checking was done to see if it was even remotely correct is a bit of a problem given the conclusion. I admittedly skimmed over certain sections but I didn't notice any discussion of the "confidence" metric that Bandit uses and this is a huge problem. Bandit only ever reported low confidence injections. Consider that for a moment: the static analysis tool reported no other type of vulnerability that was low confidence, and that includes a break-out for XSS. Every other category was Medium- or High-confidence only.

Having worked extensively with a variety of static analysis tools they vary in quality by language and detection capabilities but are generally very poor measures of application security and are often rife with false positives. The underlying premise of the paper's conclusion is that Bandit is trustworthy enough of a tool to merit the conclusion that "security issues are common in PyPI packages."

Having some experience with it in the past, I disagree with that foundational assumption. Bandit is good at finding certain classes of issues but is overall not something to rely upon for anything more than sanity-check catching egregious types of problems. For example, I'd rate it quite highly on detecting the use of the "generally avoid this" functions. A good regex could also detect these. I would not trust the XSS findings, though no doubt some are correct.

[1]: https://packaging.python.org/guides/analyzing-pypi-package-d...

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#19
post #8
post #7

Earlier quoted context omitted.

why is mktemp insecure?

Python mktemp has been deprecated since 2003. I there’s a race condition that allows a malicious process to slip in a file or symlink with different permissions at the path mktemp returns.

Just for clarity, the race condition seems deliberate. It just returns a path and leaves it to you to create the file.

Re: A Large-Scale Security-Oriented Static Analysis of Python Packages in PyPI

#20
post #15

The article is about running Bandit over PyPI, but I presume there are other options for this than Bandit. What is everyone's favourite security oriented static analysis tool for Python code?

Pysa - https://engineering.fb.com/2020/08/07/security/pysa/
Post reply on HN