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.
pip install flake8-banditNo compatibility data collected yet for this library.
Install flake8-bandit and then simply run the `flake8` command on your Python project. flake8-bandit automatically registers itself and runs Bandit's security checks. You can configure specific Bandit tests using a `.bandit` configuration file in your project root.
Create or modify a `.bandit` file in your project root to customize Bandit's behavior, for example: ```ini [bandit] exclude = /tests,/docs tests = S101,S102 ```
When ignoring or selecting specific security rules, always refer to them with the 'S' prefix in your `.flake8`, `setup.cfg`, or `pyproject.toml` configuration (e.g., `ignore = S101`).
Downgrade `flake8` to a version prior to 5.0.0 (e.g., `pip install flake8==4.0.1`) or upgrade `flake8-bandit` to a version compatible with newer `flake8` versions if available.
To ignore S101 in test files, add `per-file-ignores = tests:S101` to your Flake8 configuration (e.g., `.flake8`, `setup.cfg`, or `pyproject.toml`). For a single line, add `# noqa: S101` at the end of the line.
Always use the 'S' prefix (e.g., `S101`, `S603`) when configuring Flake8 to ignore or select rules that originate from `flake8-bandit` in your `.flake8`, `setup.cfg`, or `pyproject.toml` file, for example: `ignore = S101,S603`.
If the input to the subprocess command is validated and trusted, you can suppress this warning using `# noqa: S603` on the relevant line. Alternatively, ensure inputs are sanitized and passed as a list of arguments rather than a single string to prevent shell injection.
Avoid using `pickle` for deserializing data from untrusted sources. Instead, opt for safer and simpler serialization formats like JSON. If `pickle` is unavoidable, implement rigorous validation of the data or cryptographic signing to ensure data integrity and authenticity before deserialization.