Skip to content

Enable flake8-bandit (Ruff "S") lint rules#3606

Open
rivassec wants to merge 1 commit into
getpelican:mainfrom
rivassec:enable-bandit-rules
Open

Enable flake8-bandit (Ruff "S") lint rules#3606
rivassec wants to merge 1 commit into
getpelican:mainfrom
rivassec:enable-bandit-rules

Conversation

@rivassec

Copy link
Copy Markdown

Summary

This PR resolves the # TODO: "S" marker in pyproject.toml by enabling the flake8-bandit security rule set with a clean, low-noise suppression strategy.

  • Test file ignores: Added a global per-file-ignores rule for pelican/tests/*. This cleanly suppresses rules that don't make sense for test suites, like S101 (asserts), S105/S106 (mock credentials), S108 (/tmp paths), and S311 (non-crypto random numbers).
  • Library inline annotations: Discovered 15 true findings in the source code. Each has been given a targeted # noqa comment with a clear context justification.
  • Deferred changes: Three findings highlight actual structural issues that require follow-up work. I chose to temporarily suppress these with specific comments so we can keep this PR strictly focused on enabling the linter without introducing stealthy behavior changes.

There are no logic or runtime behavior changes in this commit.

Why

This check has been sitting on the maintainer wishlist for a while but was blocked by the backlog of existing violations. By unblocking it now, we ensure every future contribution gets automatic static security analysis. The actual code issues we found are now cleanly surfaced and tracked rather than being buried in generic technical debt.

Test plan

  • Run pdm lint --diff to confirm the formatting is green.
  • Run pdm run pytest pelican/tests -q to verify all 312 tests still pass.
  • Run ruff check --select S to ensure the new ruleset runs cleanly.

Follow-up work

These items were intentionally left out of this PR to avoid breaking changes, but they should be tackled next:

  • Replace the assert statements used for control flow in pelican_import.py (which get completely stripped out if Python runs with optimizations).
  • Migrate pelican/server.py away from the deprecated ssl.wrap_socket toward ssl.SSLContext.
  • Audit the shell=True subprocess call used during the WordPress pandoc import step.

Addresses the `# TODO: "S"` marker in pyproject.toml. Adds a per-file
ignore for `pelican/tests/*` covering S-rules that are universally
appropriate to suppress in test code (S101 assert, S105/S106 hardcoded
test passwords, S108 /tmp paths, S311 non-cryptographic randomness,
S603/S607 subprocess fixtures, S104 loopback bindings).

Each remaining library finding gets a targeted `# noqa` with a
justification comment explaining why the call is acceptable in
context. Two `S101` suppressions in `pelican_import.py` and one
`S504` in `server.py` flag latent issues that warrant follow-up but
are intentionally deferred so this commit stays purely lint-enabling.

No behavior changes.
@rivassec

Copy link
Copy Markdown
Author

FWIW the main role of this PR is to start rolling out bandid

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.

1 participant