-
Notifications
You must be signed in to change notification settings - Fork 0
[Ruff] Enable security ruff rules ("S") #97
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
base: main
Are you sure you want to change the base?
Conversation
| """Download to a temporary file and return its path.""" | ||
| import urllib.request | ||
|
|
||
| artifact_url = f"https://github.com/ollama/ollama/releases/download/{artifact_version}/{artifact_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function was always used to download an artifact and is not meant as a generic "download" function, I moved the construction of the URL directly in the function so that the linter can see that we are only opening a https URL.
| stdout = subprocess.DEVNULL | ||
|
|
||
| proc = subprocess.Popen( | ||
| proc = subprocess.Popen( # noqa: S603 We're always running Ollama |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a noqa is the only way to suppress this rule: the linter doesn't manage to figure out whether we control and trust the command run in the subprocess
| query_bytes = file.read_bytes() | ||
| query = query_bytes.decode("utf-8") | ||
| checksum = hashlib.md5(query_bytes).hexdigest() | ||
| checksum = hashlib.md5(query_bytes, usedforsecurity=False).hexdigest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've read, it's fine to use MD5 for checksums (which is not a "security" usage).
We could replace it with a sha256 though, we'd just need to check the size of the DB column, to make sure it still fits
What?
This PR enables the S ruff rules, that add linting rules checking the security of our code.
This is reproducing https://pypi.org/project/flake8-bandit
How?
I had to exclude "S608" that checks that SQL query strings should be static because we are creating a lot of SQL queries using formatted strings.
This might be something we want to look into at some point, although I think most of them should be harmless as we are using internal variables to create the string rather than any user input.