Skip to content

[Advanced]: Add Bandit security scanning (CI + pre-commit hook) #2039

@exploreriii

Description

@exploreriii

🧠 Advanced Contributors — Prerequisites & Expectations

🐞 Problem Description

We can benefit from python-specific security checks at the pre-commit level and in workflows, that supplement the codacy/existing bandit checks in .codacy.yml.

Read about bandit https://bandit.readthedocs.io/en/1.9.4/start.html

Introduce Python security linting using Bandit in both CI (GitHub Actions) and as a local pre-commit hook. This ensures early detection of insecure patterns during development and consistent enforcement in pull requests.

We would like to:

  • Provide fast feedback locally via pre-commit
  • Enforce checks centrally via CI, present results in a thoughtful way
  • Align with existing security tooling (e.g. CodeQL, dependency scanning)
  • Be achieved in a maintainable way that can scale if we add more hooks or change workflows
  • Test to see if it keeps good developer experience, what happens if there are existing issues. Do we need documentation? What kind of issues could this cause?

Double check how much codacy already is checking, and double check the above is reasonable. Research is important as the plan is not fully defined.

Caution

This advanced issue requires extensive independent research and testing.

🏁 Concrete Prerequisites

  • Proven History: Successfully merged ≥ 5 non-trivial intermediate issues in this repo, including at least 2 relating to github actions.
  • Expertise: Deep architectural understanding of creating high-quality, well tested workflows

⚠️ AI Usage Policy

Using AI to generate code for Advanced issues is strictly discouraged. AI may be used only to help explain file relationships. We require this workflow to work and follow best principles.

⏱️ Timeline & Workflow

  • Typical time: ~2 weeks / ~20 hours.
  • 🔴 Completing an advanced issue in 1–3 days is a red flag and will likely be rejected.
  • Advised: Post your proposed architectural approach as a comment and wait for feedback before writing any code.

🛠️ Implementation Notes

Technical domains involved in this issue:

  • CI/CD Integration
    GitHub Actions workflow setup, triggers (push, pull_request), permissions (security-events: write), and job configuration.
  • Static Application Security Testing (SAST)
    Use of Bandit for Python AST-based security analysis, rule coverage, and handling false positives.
  • Dependency & Tooling Management
    Installing and versioning Bandit in CI and pre-commit environments.
  • Developer Experience (DX) / Pre-commit Hooks
    Local enforcement via pre-commit, ensuring fast feedback loops and consistent developer setup.
  • Configuration & Noise Reduction
    Optional Bandit configuration (bandit.yaml), excluding directories (e.g. tests/), and tuning rules to reduce false positives.
  • Security Workflow Integration
    Ensuring Bandit complements existing tools (e.g. CodeQL, dependency scanning) without redundant coverage.

🛡️ Quality & Review Standards

The bar for advanced PRs is "safe, maintainable, architecturally sound, and production-ready."

  • CI Reliability. Workflow must run consistently on appropriate trigger
  • Proper lowest permissions set to limited scope files
  • Bandit findings are meaningful and appropriate
  • Suitably complements existing tools (e.g. CodeQL)
  • Workflow file is simple, readable, and minimal. Uses stable, well-supported GitHub Actions with hashes.
  • Pre-commit hook is appropriate with minimal friction

Notably: Developer architects the solution of how to best apply bandit to the repo

✅ PR Quality Checklist

Before opening your PR, the contributor must confirm:

  • I understand the system-wide impact of these changes on affected modules and performance.
  • The system design fits with current architectural approaches.
  • I have tested my changes extensively against both local and network environments.
  • Every line of code is personally understood and explainable and tested

📚 Resources & Support

Sample from github:
https://github.com/actions/starter-workflows/blob/main/code-scanning/bandit.yml

Project References:

🆘 Stuck?

Metadata

Metadata

Assignees

Labels

advancedrequires knowledge of multiple areas in the codebase without defined steps to implement or examplesgithub_actionsPull requests that update Github Actions code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions