Run Python Bandit scan on your codebase.
Bandit is a tool designed to find common security issues in Python code. This action will run Bandit on your codebase. The results of the scan will be found under the Security tab of your repository.
This fork retains its own branding and dependency automation while incorporating upstream fixes:
- Support a Bandit YAML or TOML config file besides the ini file
- Automatic dependency updates and SHA-pinned action dependencies managed by Renovate (rather than a second updater via Dependabot)
To run a bandit scan include a step like this:
name: Bandit Security Scanner
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '36 6 * * 0'
permissions:
contents: read
jobs:
bandit:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Bandit Scanner
uses: DevSecNinja/python-bandit-scan@v1
with: # optional arguments
# exit with 0, even with results found
exit_zero: true # optional, default is DEFAULT (exit with results-based value)
# Github token of the repository (automatically created by Github)
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information.
# File or directory to run bandit on
# path: # optional, default is .
# Report only issues of a given severity level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything)
# level: # optional, default is UNDEFINED
# Report only issues of a given confidence level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything)
# confidence: # optional, default is UNDEFINED
# comma-separated list of paths (glob patterns supported) to exclude from scan (note that these are in addition to the excluded paths provided in the config file) (default: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg)
# excluded_paths: # optional, default is DEFAULT
# comma-separated list of test IDs to skip
# skips: # optional, default is DEFAULT
# path to a .bandit file that supplies command line arguments
# ini_path: .bandit
# path to a YAML or pyproject.toml configuration file
# config_path: bandit.yml
# use a distinct artifact name to avoid collisions
# artifact_name: bandit-results
# fail on a name collision instead of deleting the existing artifact
# artifact_overwrite: 'false'
Optional The path to run bandit on
Default "."
Optional Report only issues of a given severity level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything).
Default "UNDEFINED"
Optional Report only issues of a given confidence level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything).
Default "UNDEFINED"
Optional Comma-separated list of paths (glob patterns supported) to exclude from scan (note that these are in addition to the excluded paths provided in the config file) (default is from the Bandit itself)
Default ".svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg"
Optional Exit with 0, even with results found (set "true" to use it)
Optional Comma-separated list of test IDs to skip
Optional Path to a .bandit file that supplies command line arguments
Optional Path to a config file (YAML or pyproject.toml) for bandit.
Use this to specify a bandit.yaml or pyproject.toml configuration file with the -c flag.
Paths containing spaces are supported. Leave this unset, empty, or set to "DEFAULT" to omit the -c flag.
Optional Name of the uploaded artifact. Use a distinct name for each scan in a matrix or workflow to avoid collisions.
This does not change the local results.sarif filename or the file uploaded to code scanning.
Default "results.sarif"
Optional Whether to replace an existing artifact with the same name in the workflow run.
Set "false" to fail on a collision without deleting the existing artifact.
Default "true"
The action will create an artifact containing the SARIF output. By default, an existing results.sarif artifact in the same workflow run is overwritten.
Use artifact_name to choose another name or artifact_overwrite: 'false' to disable replacement.
After installing the action's dependencies (pip install 'bandit[toml]' bandit-sarif-formatter), run the metadata regression tests with:
python -m unittest discover -s tests -v- 🙇 This is a fork of python-bandit-scan by shundor.
- 🙇 This action is based on bandit-action by Melih Değiş.
- 🙇 This action also includes fixes proposed by Kenta Nakase and Thiago Grisolfi and "MrFired" ... 🎉 but automated by @dependabot[bot]