Skip to content

Conversation

@JulienArzul
Copy link
Collaborator

@JulienArzul JulienArzul commented Jan 29, 2026

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.

"""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}"
Copy link
Collaborator Author

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

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()
Copy link
Collaborator Author

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

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

Successfully merging this pull request may close these issues.

2 participants