flake8-bandit
flake8-bandit is a plugin for Flake8 that integrates the Bandit security linter directly into your Python code quality workflow. It automates security testing by scanning Python code for common security issues and vulnerabilities, reporting them as standard Flake8 errors. The current version is 4.1.1, released on August 29, 2022, with an irregular release cadence.
Warnings
- gotcha flake8-bandit uses a dedicated `.bandit` configuration file for fine-grained control over which security tests to include or exclude. This configuration is separate from Flake8's general configuration files (e.g., `.flake8`, `setup.cfg`).
- gotcha flake8-bandit reports security issues using error codes prefixed with 'S' (e.g., S101, S501). Users familiar with Bandit's native output (which uses 'B' prefixes) or other Flake8 plugins might need to adjust their `ignore` or `per-file-ignores` rules in Flake8's configuration to match the 'S' prefix.
Install
-
pip install flake8-bandit
Quickstart
# Install flake8-bandit (flake8 and bandit will be installed as dependencies)
pip install flake8-bandit
# Run flake8-bandit on your project (it integrates automatically with flake8)
# Example: Create a file named 'insecure_code.py'
# with content: 'import subprocess; subprocess.call("ls", shell=True)'
# Then run: flake8 insecure_code.py
# Expected output for the insecure_code.py example:
# insecure_code.py:1:22: S602 Use of subprocess.call with shell=True is insecure. Consider using subprocess.run with shell=False. (subprocess-run-with-shell-equals-true)