regebro / pyroma

Rate your Python packages package friendliness
MIT License
213 stars 21 forks source link

CVE-2007-4559 Patch #89

Closed TrellixVulnTeam closed 1 year ago

TrellixVulnTeam commented 1 year ago

Patching CVE-2007-4559

Hi, we are security researchers from the Advanced Research Center at Trellix. We have began a campaign to patch a widespread bug named CVE-2007-4559. CVE-2007-4559 is a 15 year old bug in the Python tarfile package. By using extract() or extractall() on a tarfile object without sanitizing input, a maliciously crafted .tar file could perform a directory path traversal attack. We found at least one unsantized extractall() in your codebase and are providing a patch for you via pull request. The patch essentially checks to see if all tarfile members will be extracted safely and throws an exception otherwise. We encourage you to use this patch or your own solution to secure against CVE-2007-4559. Further technical information about the vulnerability can be found in this blog.

If you have further questions you may contact us through this projects lead researcher Kasimir Schulz.

CAM-Gerlach commented 1 year ago

This doesn't appear to be a huge threat; its certainly possible that an attacker could have malicious sdists with directory traversal, on PyPI or (perhaps) locally, but given they contain arbitrary executable code, once run they can do anything they want anyway, so that seems like a much more likely attack vector. Funny enough, the same was even more true of our usage in Spyder—they were used to save and restore the user's own Python session, which inherently involves executing arbitrary code, so the BadTAR attack was purely academic (since any sane attacker would simply include their malicious code right within the pickle, rather than relying on a more complex, fragile and limited BadTar exploit chain)—but funny enough, they still featured us on their blog.

This PR has some linting issues, and there doesn't appear to be any reason to define these as nested functions, while the file is open within the context manager no less, as opposed to normal module-level functions, other than automating mass PRs, whereas doing so would be more idiomatic, efficient, safe and re-usable.

However, it doesn't hurt to patch this; based on experience they won't respond here, but I could apply the same patch we did on spyder-ide/spyder-kernels#428 , if you think this is worth doing @regebro

regebro commented 1 year ago

Yes, I think it's a good idea to do something about this. And I like the spyder implementation better.

CAM-Gerlach commented 1 year ago

Thanks @regebro , opened as PR #90 for your review with some additional simplification using pathlib and minor tweaks to follow Pyroma's conventions (Black, etc).