Repository navigation
ci: hard-block external-fork PRs; ban pull_request_target except audited project_automation.yml (closes #2757) - #2759
Conversation
…uest_target (#2757) Two related hardening changes: 1. **Hard-block fork PRs** on the 6 workflows that trigger on `pull_request:` — `build_esp32s3`, `build_teensy41`, `build_uno`, `build_wasm`, `example_test_linux`, `unit_test_linux`. Add a job-level `if:` guard: if: github.event.pull_request == null || github.event.pull_request.head.repo.full_name == github.repository The first clause lets `push` / `workflow_dispatch` / `schedule` / etc. continue to run (those events have no `pull_request` context). The second clause matches only when the PR head repo IS the base repo (i.e. branch in FastLED/FastLED, never a fork). Behavior change: external-fork PRs now skip the entire build matrix silently (the jobs evaluate to `skipped`, not failed). Internal-branch PRs and pushes are unaffected. 2. **Ban pull_request_target** entirely. The only active user was `project_automation.yml`, which used it to keep a project board in sync with PR open/close/draft events. That trigger is removed; the `issues:` trigger remains. PR-driven board sync is intentionally dropped — the trigger has historically been the highest-risk surface in GitHub Actions (it runs in trusted context with secrets even on fork PRs) and the user explicitly banned it. The `build_clone_and_compile.yml` file already had `pull_request_target` disabled via comment — that pre-existing decision is now in line with repo policy. Verification: - `grep -rln 'pull_request_target' .github/` returns only two files, both showing the trigger inside a comment (one historical, one new), zero active uses. - `bash lint` clean. Filed under issue #2757 (which surfaced the cost-control concern after external PR #2752 triggered the full CI matrix; user's follow-up directives during review escalated to a hard block on fork PRs and a full ban on pull_request_target). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughJob-level ChangesExternal Fork PR Cost Control
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ment safety invariants Reverses the part of the previous commit that removed pull_request_target from project_automation.yml. The trigger is needed for PR-side project board sync (open / close / draft state changes) — a vanilla pull_request trigger has no access to the App private key required to write to the project, so pull_request_target is the only viable option. The pull_request_target ban from the previous commit still applies to the rest of the repo — project_automation.yml is the documented exception. This commit also adds a 30-line security comment block above the trigger declaration encoding the FIVE invariants that make this specific pull_request_target usage safe: 1. NEVER add `ref:` to actions/checkout (must stay on base ref) 2. NEVER run a fork-controlled script (only `python ci/github_project_sync.py`) 3. NEVER interpolate PR-controlled data into `run:` blocks (use `env:` only) 4. Keep `permissions:` minimal (currently `contents: read`) 5. App token must remain project-scoped only A second comment marker is placed directly on the actions/checkout step warning future editors not to add `ref:`. Audit performed 2026-06-04 under #2757. All five invariants verified holding. The script `ci/github_project_sync.py` was also audited: - inputs read only via `os.environ.get()` - passed to `gh api` via `-f`/`-F` positional flags (no shell) - GraphQL queries use `$variable` placeholders (no string concat) - env vars contain only GitHub-controlled metadata + repo vars + App token Net effect: identical functional behavior to pre-#2759 state on project_automation.yml; the explicit invariant comments are maintenance-grade documentation to prevent future regressions. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #2757.
What this PR does
Two related GitHub Actions hardening changes per user directive:
1. Hard-block external-fork PRs on all six
pull_request-triggered workflowsAdds a job-level
if:guard to the entry job of:.github/workflows/build_esp32s3.yml.github/workflows/build_teensy41.yml.github/workflows/build_uno.yml.github/workflows/build_wasm.yml.github/workflows/example_test_linux.yml.github/workflows/unit_test_linux.ymlThe guard:
push/workflow_dispatch/scheduleevents have nopull_requestcontext → always pass.FastLED/FastLED. Fork PRs (e.g.JChalka/FastLED:master→FastLED/FastLED:master) fail this and the job evaluates toskipped.User directive: "I do not want to run any workflow on any external fork that sends a PULL REQUEST. No exceptions."
2. Ban
pull_request_target, with ONE documented exception (project_automation.yml)User directive: "ban pull_request_target", followed by "actually okay project_automation.yml needs it on pull request trigger but you must audit it for problems".
Active
pull_request_targettriggers after this PR: exactly one —project_automation.yml. It's needed for PR-side project board sync (no other trigger has access to the App private key required to write to the project from a fork PR event).build_clone_and_compile.yml: already hadpull_request_targetdisabled via comment from a prior security incident — that pre-existing decision stays.Audit of
project_automation.yml(the one exception)Verified holding all five safety invariants of safe
pull_request_targetusage:ref:on checkout (checkout must stay on base ref, NOT PR head)actions/checkout@v4step has noref:parameter.sparse-checkout: cifurther limits surface.run:step ispython ci/github_project_sync.py— a path that, by virtue of invariant #1, is base-controlled.run:blocks${{ ... }}expressions sit insideenv:blocks. Therun:itself is a literal command. (Anti-injection pattern documented in GitHub's "Security hardening for GitHub Actions" guide.)permissions:permissions: contents: read. No write scope on default GITHUB_TOKEN.actions/create-github-app-token@v3mints a token that the App installation grants only project read/write. (Repo-level confirmation outside this PR — relies on App installation config.)Also audited
ci/github_project_sync.pyitself:os.environ.get()gh api graphqlvia positional-f/-Fflags (no shell interpolation)$variableplaceholders, not Python string concatenationgithub.event.issue.node_id,github.event.pull_request.node_id,github.event_name,github.event.action), repovars.*, and the App private keyHardening added in this PR: a 30-line security-comment block above the
pull_request_target:declaration inproject_automation.ymlencoding all five invariants in-source, plus a second comment marker on theactions/checkoutstep warning future editors not to addref:. This converts the unenforced-convention safety into self-documenting tripwires for future PRs touching the file.Behavior change
mastermastermasterproject_automation.ymlpull_request_targetpull_request_targetpull_request_target(unchanged)Verification
What this PR does NOT do (intentional follow-ups)
actions/checkout@v4,actions/setup-python@v5,actions/create-github-app-token@v3inproject_automation.yml— defensive hardening worth doing but separate from the fork-block scope.Settings → Actions → General → Fork pull request workflows from outside collaborators— recommended defense-in-depth (Require approval for all outside collaborators) but a UI action.secrets.*to apull_request-reachable workflow — recommended in ci: prevent fork PRs from auto-triggering the full CI matrix (cost control — surfaced by #2752) #2757 thread, separate PR.FastLED/fbuild/.github/actions/setup@main(mutable ref on external action) — unrelated supply-chain concern.🤖 Generated with Claude Code
Summary by CodeRabbit
Chores
Documentation