A stranger forks your repo, adds one line to a build script that posts your environment to their server, and opens a pull request. A maintainer types /deploy to get a preview. Your workflow checks out the PR, runs the build next to your deploy token, and the token is gone. This is a "pwn request", and it works because a workflow triggered by issue_comment runs in your repo with your secrets, even when the comment is on a PR from a fork.
The fix is a gate that runs before any job with secrets. It refuses PRs from forks, checks that the commenter can write to the repo, and pins the commit it checked, so every later job builds that same commit.
The pull_request trigger is safe for forks. A PR from a fork gets no secrets and a read-only GITHUB_TOKEN.
issue_comment is different. It runs the workflow from your default branch, in your repo, with your secrets and a write-scoped token. pull_request_target and workflow_run behave the same way. That is fine until the workflow checks out the PR's code. From then on, every npm ci, build script and test runs whatever the PR author wrote.
The command does not protect you. The attack fires in 2 ways:
/deployrefs/pull/N/merge, which moves every time the PR changes, so it can build code nobody approvedon:issue_comment:types: [created]jobs:deploy:if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/deploy')runs-on: ubuntu-lateststeps:- uses: actions/checkout@v7with:ref: refs/pull/${{ github.event.issue.number }}/merge- run: npm ci && npm run build- run: ./deploy.shenv:DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
❌ Figure: Bad example - Anyone who can open a PR can rewrite deploy.sh and run it next to your deploy token
Scoping the secret to one step does not help here. The PR's code ran earlier in the same job, so it can change deploy.sh before that step starts.
Put these checks in a gate job that every other job needs. If any check fails, the gate exits with an error and nothing with secrets runs.
write or above. On a public repo, anyone can commentrefs/pull/N/merge. A push after the gate runs can't change what gets built. Someone with write access can still push between the comment and the gate, so if that matters, make the command include the SHA (e.g. /deploy 1a2b3c4) and refuse a mismatchpermissions: on each job, and give each job only the secrets it usesjobs:gate:if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/deploy')runs-on: ubuntu-latestpermissions:pull-requests: readoutputs:head_sha: ${{ steps.check.outputs.head_sha }}steps:- id: checkenv:GH_TOKEN: ${{ github.token }}PR: ${{ github.event.issue.number }}ACTOR: ${{ github.event.comment.user.login }}run: |read -r head_repo head_sha < <(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq '"\(.head.repo.full_name) \(.head.sha)"')[[ "$head_repo" == "$GITHUB_REPOSITORY" ]] || { echo "Refusing a PR from a fork"; exit 1; }role=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$ACTOR/permission" --jq .permission)[[ "$role" == "admin" || "$role" == "write" ]] || { echo "Commenter needs write access"; exit 1; }echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT"build:needs: gateruns-on: ubuntu-latestpermissions:contents: readsteps:- uses: actions/checkout@v7with:ref: ${{ needs.gate.outputs.head_sha }}persist-credentials: false- run: npm ci && npm run build- uses: actions/upload-artifact@v7with:name: sitepath: distdeploy:needs: buildruns-on: ubuntu-latestpermissions: {}environment: previewsteps:- uses: actions/download-artifact@v8with:name: site- uses: your-org/deploy-action@v1with:path: .token: ${{ secrets.DEPLOY_TOKEN }}
✅ Figure: Good example - The gate refuses forks and outsiders, the build has no secrets, and only the deploy job sees the token
Treat the artifact as data. The deploy job uploads it, but never runs a script that came out of it.
Pin third-party actions like your-org/deploy-action to a full commit SHA. A tag can be moved to new code, and that code would run next to your token.
Run it with the pull_request trigger, which gives the fork no secrets. If a fork PR needs a preview deploy, a maintainer reviews the change and pushes it to a branch in your repo. The command then runs on that branch, which passes the gate.
Tip: Wrap the gate in a composite action, so every workflow with a comment command runs the same checks in the same order.
/command