Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a linter to ban certain Python imports #1230

Open
rntz opened this issue Jul 13, 2023 · 4 comments
Open

Use a linter to ban certain Python imports #1230

rntz opened this issue Jul 13, 2023 · 4 comments

Comments

@rntz
Copy link
Collaborator

rntz commented Jul 13, 2023

@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
Copy link
Collaborator

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
Copy link
Collaborator

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

@wenkokke
Copy link
Collaborator

wenkokke commented Jul 13, 2023

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants