4 ms·
Having written code in Python for a few years, I've come across most of these (some of the ways to hack builtins/modify the code on a function reference were ne
by tehwalrus 10y ago
Having written code in Python for a few years, I've come across most of these (some of the ways to hack builtins/modify the code on a function reference were new to me).
However, it had also never occurred to me to make anything I cared about the security of in python. Perhaps this article is aimed at people who are writing system utilities for linux distributions, and are considering Python? Presumably some such utilities are written that way already.
It comes down to doing a proper security analysis before you define the requirements of the software: Specifically what attack vectors you want to defend against. A valid conclusion for some types of software, given the list of "bugs" in the post, would be don't write it in Python. (Indeed, I have done exactly this before writing 200 lines of C instead of 20 lines of Python.)
- viraptor 10y ago> A valid conclusion for some types of software, given the list of "bugs" in the post, would be don't write it in Python. Do you have some specific types in mind? I know some types of protection are not reachable from python directly and require native modules, but I'm not sure what would cause you to drop Python altogether. I'd be interested to hear some examples.
- tehwalrus 10y agoWell, for example, you might want to write a package manager for a Linux distribution[1]. An attacker could change the behaviour of someone's package manager by some non-privileged means (messing with the user's python path and placing an evil self-hiding module that changes the behaviour of the engine e.g. by always listing a malicious package as a dependency of whatever you're currently installing). The problematic code here is Python's `import` mechanism and mutable global references to standard library functions. You can cut out the "buggy" code by writing in another language. [1] https://wiki.gentoo.org/wiki/Python https://wiki.gentoo.org/wiki/Python
- viraptor 10y agoThat's possible, but I don't think it's relevant. If you have access to the user's profile, it doesn't really matter what language the package manager uses. You still have rights to create aliases, create local wrapper scripts, use LD_PRELOAD, set LD_LIBRARY_PATH, and many other ways to execute your own code. You can stop the user accessing the original package manager in the first place. dnf for example is widely used (Fedora's default package manager) and it's written in Python: https://github.com/rpm-software-management/dnf https://github.com/rpm-software-management/dnf