Created
May 12, 2026 11:34
-
-
Save elithrar/1c5bbc16d4907b28ac320c46fed3aca8 to your computer and use it in GitHub Desktop.
pull_request_target considered harmful - https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .github/workflows/no-pull-request-target.yml | |
| name: pull_request_target considered dangerous | |
| on: | |
| pull_request: | |
| paths: | |
| - ".github/workflows/**/*.yml" | |
| - ".github/workflows/**/*.yaml" | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - ".github/workflows/**/*.yml" | |
| - ".github/workflows/**/*.yaml" | |
| permissions: | |
| contents: read | |
| jobs: | |
| deny-pull-request-target: | |
| name: pull_request_target considered dangerous | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Fail if any workflow uses pull_request_target | |
| shell: bash | |
| run: | | |
| RULE="$(cat <<'EOF' | |
| id: no-pull-request-target | |
| language: Yaml | |
| severity: error | |
| message: pull_request_target considered dangerous | |
| rule: | |
| any: | |
| - kind: string_scalar | |
| regex: '^pull_request_target$' | |
| - kind: double_quote_scalar | |
| regex: '^"pull_request_target"$' | |
| - kind: single_quote_scalar | |
| regex: "^'pull_request_target'$" | |
| EOF | |
| )" | |
| npx --yes --package @ast-grep/cli@0.42.2 ast-grep scan .github/workflows \ | |
| --no-ignore hidden \ | |
| --globs '**/*.yml' \ | |
| --globs '**/*.yaml' \ | |
| --format github \ | |
| --inline-rules "$RULE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment