01 · Before and afterThe pattern
- uses: actions/checkout@<sha>
with: { persist-credentials: false }
- run: npm ci # PR-controlled postinstall scripts see no token
- run: |
git add "$OUT"
git diff --staged --quiet -- "$OUT" && exit 0 # also catches new files
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" push origin HEAD:"$REF"
env: { TOKEN: ${{ secrets.GITHUB_TOKEN }} }02 · Run it on your appThe check
In your CI, does any step that installs or runs PR code run after a checkout that persisted a write token?
If the honest answer is no or not sure, this is worth a look before it reaches production.