|
| 1 | +name: Exclusions Updater |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + #- cron: '0 5 * * 0' # Runs at 05:00 every Sunday |
| 6 | + - cron: '0 5 * * *' # Runs at 05:00 every day |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + update-exclusions: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v5 |
| 15 | + |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v6 |
| 18 | + with: |
| 19 | + python-version: '3.13' |
| 20 | + |
| 21 | + - name: Install Poetry |
| 22 | + uses: abatilo/actions-poetry@v4 |
| 23 | + with: |
| 24 | + poetry-version: 'latest' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: | |
| 28 | + poetry install --no-interaction --with dev |
| 29 | +
|
| 30 | + - name: Run false positive tests |
| 31 | + run: | |
| 32 | + $(poetry env activate) |
| 33 | + pytest -q --tb no -m validate_targets_fp -n 20 | tee fp_test_results.txt |
| 34 | + deactivate |
| 35 | +
|
| 36 | + - name: Parse false positive detections by desired categories |
| 37 | + run: | |
| 38 | + grep -oP '(?<=test_false_pos\[)[^\]]+(?=\].*result was Claimed)' fp_test_results.txt \ |
| 39 | + | sort -u > false_positive_exclusions.txt |
| 40 | + grep -oP '(?<=test_false_pos\[)[^\]]+(?=\].*result was WAF)' fp_test_results.txt \ |
| 41 | + | sort -u > waf_hits.txt |
| 42 | +
|
| 43 | + - name: Detect if exclusions list changed |
| 44 | + id: detect_changes |
| 45 | + run: | |
| 46 | + git fetch origin exclusions || true |
| 47 | +
|
| 48 | + if git show origin/exclusions:false_positive_exclusions.txt >/dev/null 2>&1; then |
| 49 | + # If the exclusions branch and file exist, compare |
| 50 | + if git diff --quiet origin/exclusions -- false_positive_exclusions.txt; then |
| 51 | + echo "exclusions_changed=false" >> "$GITHUB_OUTPUT" |
| 52 | + else |
| 53 | + echo "exclusions_changed=true" >> "$GITHUB_OUTPUT" |
| 54 | + fi |
| 55 | + else |
| 56 | + # If the exclusions branch or file do not exist, treat as changed |
| 57 | + echo "exclusions_changed=true" >> "$GITHUB_OUTPUT" |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Quantify and display results |
| 61 | + run: | |
| 62 | + FP_COUNT=$(wc -l < false_positive_exclusions.txt | xargs) |
| 63 | + WAF_COUNT=$(wc -l < waf_hits.txt | xargs) |
| 64 | + echo ">>> Found $FP_COUNT false positives and $WAF_COUNT WAF hits." |
| 65 | + echo ">>> False positive exclusions:" && cat false_positive_exclusions.txt |
| 66 | + echo ">>> WAF hits:" && cat waf_hits.txt |
| 67 | +
|
| 68 | + - name: Commit and push exclusions list |
| 69 | + if: steps.detect_changes.outputs.exclusions_changed == 'true' |
| 70 | + run: | |
| 71 | + git config user.name "Paul Pfeister (automation)" |
| 72 | + git config user.email "[email protected]" |
| 73 | +
|
| 74 | + mv false_positive_exclusions.txt false_positive_exclusions.txt.tmp |
| 75 | +
|
| 76 | + git add -f false_positive_exclusions.txt.tmp # -f required to override .gitignore |
| 77 | + git stash push -m "stash false positive exclusion list" -- false_positive_exclusions.txt.tmp |
| 78 | +
|
| 79 | + git fetch origin exclusions || true # Allows creation of branch if deleted |
| 80 | + git checkout -B exclusions origin/exclusions || (git checkout --orphan exclusions && git rm -rf .) |
| 81 | +
|
| 82 | + git stash pop || true |
| 83 | +
|
| 84 | + mv false_positive_exclusions.txt.tmp false_positive_exclusions.txt |
| 85 | +
|
| 86 | + git rm -f false_positive_exclusions.txt.tmp || true |
| 87 | + git add false_positive_exclusions.txt |
| 88 | + git commit -m "auto: update exclusions list" || echo "No changes to commit" |
| 89 | + git push origin exclusions |
0 commit comments