|
| 1 | +name: 'Bandit Scan' |
| 2 | +description: 'Bandit Scan' |
| 3 | +inputs: |
| 4 | + path: |
| 5 | + description: 'File or directory to run bandit on' |
| 6 | + required: false |
| 7 | + default: '.' |
| 8 | + level: |
| 9 | + description: 'Report only issues of a given severity level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything)' |
| 10 | + required: false |
| 11 | + default: 'UNDEFINED' |
| 12 | + confidence: |
| 13 | + description: 'Report only issues of a given confidence level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything)' |
| 14 | + required: false |
| 15 | + default: 'UNDEFINED' |
| 16 | + excluded_paths: |
| 17 | + description: '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)' |
| 18 | + required: false |
| 19 | + default: 'DEFAULT' |
| 20 | + exit_zero: |
| 21 | + description: 'exit with 0, even with results found' |
| 22 | + required: false |
| 23 | + default: 'DEFAULT' |
| 24 | + skips: |
| 25 | + description: 'comma-separated list of test IDs to skip' |
| 26 | + required: false |
| 27 | + default: 'DEFAULT' |
| 28 | + ini_path: |
| 29 | + description: 'path to a .bandit file that supplies command line arguments' |
| 30 | + required: false |
| 31 | + default: 'DEFAULT' |
| 32 | + GITHUB_TOKEN: |
| 33 | + description: 'Github token of the repository (automatically created by Github)' |
| 34 | + required: true |
| 35 | + |
| 36 | +runs: |
| 37 | + using: composite |
| 38 | + steps: |
| 39 | + - name: Install dependencies |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + pip install bandit bandit-sarif-formatter |
| 43 | +
|
| 44 | + - name: Run Bandit scan |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + UPPERCASE_LEVEL=$(echo $INPUT_LEVEL | tr a-z A-Z) |
| 48 | + case $UPPERCASE_LEVEL in |
| 49 | + LOW) |
| 50 | + LEVEL="-l" |
| 51 | + ;; |
| 52 | + MEDIUM | MID) |
| 53 | + LEVEL="-ll" |
| 54 | + ;; |
| 55 | + HIGH) |
| 56 | + LEVEL="-lll" |
| 57 | + ;; |
| 58 | + *) |
| 59 | + LEVEL="" |
| 60 | + ;; |
| 61 | + esac |
| 62 | +
|
| 63 | + UPPERCASE_CONFIDENCE=$(echo $INPUT_CONFIDENCE | tr a-z A-Z) |
| 64 | + case $UPPERCASE_CONFIDENCE in |
| 65 | + LOW) |
| 66 | + CONFIDENCE="-i" |
| 67 | + ;; |
| 68 | + MEDIUM | MID) |
| 69 | + CONFIDENCE="-ii" |
| 70 | + ;; |
| 71 | + HIGH) |
| 72 | + CONFIDENCE="-iii" |
| 73 | + ;; |
| 74 | + *) |
| 75 | + CONFIDENCE="" |
| 76 | + ;; |
| 77 | + esac |
| 78 | +
|
| 79 | + if [ "$INPUT_EXCLUDED_PATHS" == "DEFAULT" ]; then |
| 80 | + EXCLUDED_PATHS="" |
| 81 | + else |
| 82 | + EXCLUDED_PATHS="-x $INPUT_EXCLUDED_PATHS" |
| 83 | + fi |
| 84 | +
|
| 85 | + if [ "$INPUT_EXIT_ZERO" == "DEFAULT" ]; then |
| 86 | + EXIT_ZERO="" |
| 87 | + else |
| 88 | + EXIT_ZERO="--exit-zero" |
| 89 | + fi |
| 90 | +
|
| 91 | + if [ "$INPUT_SKIPS" == "DEFAULT" ]; then |
| 92 | + SKIPS="" |
| 93 | + else |
| 94 | + SKIPS="-s $INPUT_SKIPS" |
| 95 | + fi |
| 96 | +
|
| 97 | + if [ "$INPUT_INI_PATH" == "DEFAULT" ]; then |
| 98 | + INI_PATH="" |
| 99 | + else |
| 100 | + INI_PATH="--ini $INPUT_INI_PATH" |
| 101 | + fi |
| 102 | + bandit -f sarif -o results.sarif -r $INPUT_PATH $LEVEL $CONFIDENCE $EXCLUDED_PATHS $EXIT_ZERO $SKIPS $INI_PATH |
| 103 | + env: |
| 104 | + INPUT_PATH: ${{ inputs.path }} |
| 105 | + INPUT_LEVEL: ${{ inputs.level }} |
| 106 | + INPUT_CONFIDENCE: ${{ inputs.confidence }} |
| 107 | + INPUT_EXCLUDED_PATHS: ${{ inputs.excluded_paths }} |
| 108 | + INPUT_EXIT_ZERO: ${{ inputs.exit_zero }} |
| 109 | + INPUT_SKIPS: ${{ inputs.skips }} |
| 110 | + INPUT_INI_PATH: ${{ inputs.ini_path }} |
| 111 | + |
| 112 | + - name: Upload artifact |
| 113 | + uses: actions/upload-artifact@main |
| 114 | + with: |
| 115 | + name: results.sarif |
| 116 | + path: results.sarif |
| 117 | + |
| 118 | + - name: Upload SARIF file |
| 119 | + uses: github/codeql-action/upload-sarif@v2 |
| 120 | + with: |
| 121 | + sarif_file: results.sarif |
| 122 | + |
| 123 | + |
0 commit comments