|
| 1 | +# NOTE: This rule leverages the `http.send` function and a Cloud Run service |
| 2 | +# https://banditize-562949304223.us-central1.run.app, which is built from |
| 3 | +# https://github.com/evankanderson/banditize |
| 4 | + |
| 5 | +# This also requires https://github.com/mindersec/minder/pull/5181 to be merged, |
| 6 | +# and the `pr_comment_alert` feature flag enabled. |
| 7 | +--- |
| 8 | +version: v1 |
| 9 | +type: rule-type |
| 10 | +name: pr_bandit |
| 11 | +severity: |
| 12 | + value: medium |
| 13 | +context: |
| 14 | + provider: github |
| 15 | +description: | |
| 16 | + Detects new python static analysis findings in a pull request. |
| 17 | +
|
| 18 | + This rule uses https://github.com/PyCQA/bandit as a code scanner, |
| 19 | + running it against the base and head branches of a pull request to |
| 20 | + detect new security issues. |
| 21 | +guidance: | |
| 22 | + This pull request introduces new issues detected by the Bandit static |
| 23 | + code scanner. Generally, these indicate risky software patterns which |
| 24 | + should be addressed before merging the pull request. |
| 25 | +def: |
| 26 | + in_entity: pull_request |
| 27 | + rule_schema: |
| 28 | + type: object |
| 29 | + properties: {} |
| 30 | + ingest: |
| 31 | + type: git |
| 32 | + git: {} |
| 33 | + # Defines the configuration for evaluating data ingested against the given profile |
| 34 | + eval: |
| 35 | + type: rego |
| 36 | + rego: |
| 37 | + type: constraints |
| 38 | + def: | |
| 39 | + package minder |
| 40 | + import rego.v1 |
| 41 | +
|
| 42 | + base_tar := base_file.archive(["."]) |
| 43 | + head_tar := file.archive(["."]) |
| 44 | +
|
| 45 | + resp := http.send({ |
| 46 | + "method": "POST", |
| 47 | + "url": "https://banditize-562949304223.us-central1.run.app/pull", |
| 48 | + "headers": { |
| 49 | + "Content-Type": "application/json", |
| 50 | + }, |
| 51 | + "body": { |
| 52 | + "base": base64.encode(base_tar), |
| 53 | + "head": base64.encode(head_tar), |
| 54 | + }, |
| 55 | + }) |
| 56 | +
|
| 57 | + violations contains {"msg": resp.body.simpleFindings} if resp.body.simpleFindings != "" |
| 58 | + # violations contains {"msg": "Always fail"} |
| 59 | + |
| 60 | + # violations contains {"msg": json.marshal(resp)} |
| 61 | + alert: |
| 62 | + type: pull_request_comment |
| 63 | + pull_request_comment: |
| 64 | + review_message: | |
| 65 | + [Bandit](https://bandit.readthedocs.io/) found new issues in this pull request. Please review and address them before merging. |
| 66 | + |
| 67 | + You'll need to run `minder profile status list -n Test-Bandit --detailed -o json | jq -r '.ruleEvaluationStatus[0].details'` to get the actual errors. |
0 commit comments