talonhub / community

Voice command set for Talon, community-supported.
MIT License
640 stars 784 forks source link

Use a linter to ban certain Python imports #1230

Open rntz opened 1 year ago

rntz commented 1 year ago

@lunixbochs thinks that for security reasons we should lint for/ban certain Python imports. From slack:

I submit this list (and any imports under them, e.g. both http and http.server should be blocked, or from http import server etc):

aiohttp
asynchat
asyncio
asyncore
cffi
ctypes
ftplib
http
idlelib
mailbox
multiprocessing
nntplib
pip
poplib
requests
smtplib
socket
socketserver
ssl
telnetlib
threading
urllib.request
urllib3

I haven't done this in python before, but import-linter doesn't seem to be the worst

cc @wenkokke

wenkokke commented 1 year ago

Using import-linter isn't tenable in the current form of the community repository, because it relies on the repository to be a Python package, i.e., we'd have to add __init__.py files to each directory. There are options for namespace packages, but they'd require us to exhaustively list all files—or at least directories, I'm unsure, haven't gotten that to work—in the package, which is untenable and incredibly error prone.

wenkokke commented 1 year ago

@lunixbochs Would there be an problems with Talon if we were to add __init__.py files to the community repository?

wenkokke commented 1 year ago

We could consider using bandit, but it does not seem to be able to work with allowlists: https://bandit.readthedocs.io/en/latest/blacklists/index.html

The import-linter package also doesn't support allowlists, but it does support blocklists with wildcards and ignore statements, which is... less than ideal, but workable.

auscompgeek commented 1 year ago

There's also flake8-tidy-imports, which is also partially implemented by ruff - I think the rule we'd want is there: https://beta.ruff.rs/docs/settings/#flake8-tidy-imports-banned-api

I think it'd also be worth running bandit.