Skip to content

About

GitHub Action for Bandit SAST

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 
 

Repository files navigation

Bandit Scanner

Run Python Bandit scan on your codebase.

About

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.

Fork

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)

Usage

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'

Inputs

path

Optional The path to run bandit on

Default "."

level

Optional Report only issues of a given severity level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything).

Default "UNDEFINED"

confidence

Optional Report only issues of a given confidence level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything).

Default "UNDEFINED"

excluded_paths

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"

exit_zero

Optional Exit with 0, even with results found (set "true" to use it)

skips

Optional Comma-separated list of test IDs to skip

ini_path

Optional Path to a .bandit file that supplies command line arguments

config_path

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.

artifact_name

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"

artifact_overwrite

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"

Outputs

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.

Testing

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

Credits

About

GitHub Action for Bandit SAST

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages