You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to discuss the use of non-pure Python package dependencies in pre-commit.
In particular the use of C code adds build difficulty and security risk, which I hope can be carefully weighed against the need for it.
Background
You could envision two possible designs of pre-commit:
a pure Python tool that can be used by dev teams in almost any setting, vs.
a CPython-dependent tool that requires custom C code, Python header files and C toolchain to install.
This trade-off is of course not particular to pre-commit.
Sure, in Python-based projects, depending on C libraries and certainly on CPython is very common.
For pre-commit however, it has more impact than usual: adding pre-commit to a CI setup is more difficult in design 2, and I see that as a major use-case (it is for me, in practice).
Current state
As far as I found, pre-commit currently
LibYAML has not seen maintainance in the last two years and is still at 0.1.6.
It is not widely available from OS packaging (e.g., not on Alpine Linux), and appears to not be installed automatically following the installation/build instructions for pre-commit.
Building without LibYAML succeeds though, so this is less of a problem.
pyterminalsize is @asottile's own, still young library.
Discussion
I am wondering, how important is it to keep pyterminalsize with just that small snippet of C code as a dependency? Is it easily possible to take a different approach, and avoid CI containers having to install a C toolchain?
That said, there are ui designs which eliminate pyterminalsize which would be great to implement (basically use either minimum required dots or fixed at 79 characters)
Manylinux wheels, didn't know them, but it looks like it isn't robust and simple. Also, isn't the interaction with Windows support problematic? A good solution perhaps if the C code in your CPython project is absolutely needed and the range of user platforms is limited and well-known in advance.
Using C code, especially for LibYAML is a security issue over using pure Python since any and all C code is at particular risk of memory security issues. See e.g. this paper. In practice, this means that someone writing malformed YAML could use that to execute arbitrary code. This kind of vulnerability happens now, to the best, and to popular widely used libraries. Moreover, the YAML spec is notoriously complex. For something potentially operating at the center of software development in an organization (e.g., on a CI host), that's unattractive.
There already exists wheels for Windows so not a problem there. I think manylinux should solve your primary gripes in ci.
I'm not sure that being written in a specific language means it is any more or less vulnerable to memory security vulnerabilities. CPython itself is written in c, should I remove cpython support /s? More seriously there are other ways in pure python to execute arbitrary code.
I hear you about yaml, I hate it :) would have rather used json from the start but it's nearly impossible to switch now and maintain any compatibility. There is one use case that yaml doesn't currently give us in rewritability -- I've planned to write a simpler round trip parser that only handles a strict subset of yaml which could alleviate your concerns there. That said, I don't think that using yaml as a configuration language means there's a problem in our case.
To conclude, I believe your only valid concern is with build system setup and not actually security. This can be solved by using (manylinux) wheels for pyterminalsize and by allowing the fallback pure python implementation of pyyaml. I can build pyterminalsize manylinux wheels when I'm at a computer.
I respectfully disagree with you that using one language over the other won't really make you more or less vulnerable to memory security vulnerabilities. As claimed in the paper and in many other, C code is particularly at risk of this. CPython is more carefully authored and reviewed than your average C code, so ceasing to use CPython isn't so inevitable.
>>># ideally, never do this>>>x=lambda: None>>>y=type(x.__code__)(*((0,) *5), b'\x01', (), (), (), '', '', 0, b'')
>>>type(x)(y, {})()
Segmentationfault (coredumped)
On the point of languages, I'll give you that it is certainly easier to write poorly written code which allows for memory issues. But I do think they are possible in any language, especially given most code needs to interface with C routines at some point.
Activity
asottile commentedon Aug 16, 2016
I believe this becomes a non issue if pyterminalsize had a built manylinux wheel is this correct?
Could you elaborate on what you mean by security issues?
asottile commentedon Aug 16, 2016
That said, there are ui designs which eliminate pyterminalsize which would be great to implement (basically use either minimum required dots or fixed at 79 characters)
sanmai-NL commentedon Aug 16, 2016
Manylinux wheels, didn't know them, but it looks like it isn't robust and simple. Also, isn't the interaction with Windows support problematic? A good solution perhaps if the C code in your CPython project is absolutely needed and the range of user platforms is limited and well-known in advance.
Using C code, especially for LibYAML is a security issue over using pure Python since any and all C code is at particular risk of memory security issues. See e.g. this paper. In practice, this means that someone writing malformed YAML could use that to execute arbitrary code. This kind of vulnerability happens now, to the best, and to popular widely used libraries. Moreover, the YAML spec is notoriously complex. For something potentially operating at the center of software development in an organization (e.g., on a CI host), that's unattractive.
asottile commentedon Aug 16, 2016
There already exists wheels for Windows so not a problem there. I think manylinux should solve your primary gripes in ci.
I'm not sure that being written in a specific language means it is any more or less vulnerable to memory security vulnerabilities. CPython itself is written in c, should I remove cpython support /s? More seriously there are other ways in pure python to execute arbitrary code.
I hear you about yaml, I hate it :) would have rather used json from the start but it's nearly impossible to switch now and maintain any compatibility. There is one use case that yaml doesn't currently give us in rewritability -- I've planned to write a simpler round trip parser that only handles a strict subset of yaml which could alleviate your concerns there. That said, I don't think that using yaml as a configuration language means there's a problem in our case.
To conclude, I believe your only valid concern is with build system setup and not actually security. This can be solved by using (manylinux) wheels for pyterminalsize and by allowing the fallback pure python implementation of pyyaml. I can build pyterminalsize manylinux wheels when I'm at a computer.
sanmai-NL commentedon Aug 16, 2016
Thanks for all the wheels.
I respectfully disagree with you that using one language over the other won't really make you more or less vulnerable to memory security vulnerabilities. As claimed in the paper and in many other, C code is particularly at risk of this. CPython is more carefully authored and reviewed than your average C code, so ceasing to use CPython isn't so inevitable.
asottile commentedon Aug 16, 2016
Should work now with pip>8 without a C compiler installed:
asottile commentedon Aug 16, 2016
It's also certainly not impossible:
On the point of languages, I'll give you that it is certainly easier to write poorly written code which allows for memory issues. But I do think they are possible in any language, especially given most code needs to interface with C routines at some point.
pypy has a more fun time: