|
3 | 3 | # |
4 | 4 | # Test now: Actions → this workflow → Run workflow. |
5 | 5 | # Smoke test: set `single_repo` to one HTTPS URL and leave org as default. |
| 6 | +# |
| 7 | +# Inputs are passed only via step `env` (not ${{ }} inside `run:`) to satisfy |
| 8 | +# zizmor template-injection rules; values are validated before use. |
6 | 9 |
|
7 | 10 | name: TruffleHog org scan (GitHub) |
8 | 11 |
|
@@ -54,17 +57,46 @@ jobs: |
54 | 57 | - name: Run scan (advisory — never blocks merges) |
55 | 58 | env: |
56 | 59 | TOKEN: ${{ secrets.ORG_TRUFFLEHOG_PAT }} |
| 60 | + # Do not interpolate workflow inputs inside `run:` (zizmor: template-injection). |
| 61 | + ORG_INPUT: ${{ github.event.inputs.org || '' }} |
| 62 | + SINGLE_REPO_INPUT: ${{ github.event.inputs.single_repo || '' }} |
| 63 | + EVENT_NAME: ${{ github.event_name }} |
57 | 64 | run: | |
58 | 65 | if [[ -z "${TOKEN}" ]]; then |
59 | 66 | echo "::error::Create repository secret ORG_TRUFFLEHOG_PAT (PAT with read access to the org repos you scan)." |
60 | 67 | exit 1 |
61 | 68 | fi |
62 | 69 |
|
| 70 | + # GitHub org slug: alphanumeric + hyphen, reasonable length (GitHub max 39). |
| 71 | + validate_org() { |
| 72 | + local o="$1" |
| 73 | + [[ "${o}" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{0,38}$ ]] |
| 74 | + } |
| 75 | +
|
| 76 | + # Single-repo smoke test: strict https://github.com/org/repo only. |
| 77 | + validate_repo_url() { |
| 78 | + local u="$1" |
| 79 | + [[ -z "${u}" ]] && return 0 |
| 80 | + [[ "${u}" =~ ^https://github\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/?$ ]] |
| 81 | + } |
| 82 | +
|
63 | 83 | ORG="${DEFAULT_ORG}" |
64 | 84 | SINGLE_REPO="" |
65 | | - if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then |
66 | | - ORG="${{ github.event.inputs.org }}" |
67 | | - SINGLE_REPO="${{ github.event.inputs.single_repo }}" |
| 85 | + if [[ "${EVENT_NAME}" == "workflow_dispatch" ]]; then |
| 86 | + if [[ -n "${ORG_INPUT}" ]]; then |
| 87 | + if ! validate_org "${ORG_INPUT}"; then |
| 88 | + echo "::error::Invalid org slug (allowed: letters, digits, hyphen; 1–39 chars)." |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + ORG="${ORG_INPUT}" |
| 92 | + fi |
| 93 | + if [[ -n "${SINGLE_REPO_INPUT}" ]]; then |
| 94 | + if ! validate_repo_url "${SINGLE_REPO_INPUT}"; then |
| 95 | + echo "::error::Invalid single_repo URL (use https://github.com/ORG/REPO with no query or fragment)." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + SINGLE_REPO="${SINGLE_REPO_INPUT}" |
| 99 | + fi |
68 | 100 | fi |
69 | 101 |
|
70 | 102 | set +e |
|
0 commit comments