Skip to content

Dataset CI shims run on pull_request_target, so fork pull requests get BIDS validation and version-check - #1784

Merged
neuromechanist merged 3 commits into
nemarOrg:devfrom
bruAristimunha:fix/fork-pr-validation-shim
Oct 24, 2026
Merged

neuromechanist merged 3 commits into
nemarOrg:devfrom
bruAristimunha:fix/fork-pr-validation-shim

Conversation

@bruAristimunha

Copy link
Copy Markdown
Contributor

Fork pull requests never get BIDS validation or version-check

The per-dataset shims bids-validation.yml and version-check.yml run on pull_request. For a pull request from a fork, GitHub gives that run no secrets, so the first step fails (Error: Input required and not supplied: app-id) and run-bids-validation / run-version-check in nemarDatasets/.github are never dispatched. Every fork PR shows a red "Dispatch central BIDS validation" and has no central checks until someone runs the central workflows by hand. Seen on nemarDatasets/nm000182#3, nm000183#3, nm000232#4 and on003825#2 (run 38716890974). For contributors with no role on the repository, the run also waits for approval first.

Change

Both shims (template in backend/src/services/github/workflows.ts):

  • pull_request -> pull_request_target (branches [main]). The run uses the file as it is on main and gets the secrets. pr-merge.yml already uses pull_request_target and runs fine for fork PRs (nm000182#3 merged today).
  • The event fields (repository.name, pull_request.head.sha, head.ref, number) are passed through env. Before, they were written into the run: script with ${{ }}, so a branch name could inject shell code. That was harmless without secrets, and must not exist with them.
  • The script checks the dataset id (nm|on|xx + 6 digits), the head sha (40 hex characters) and the PR number before calling gh. The branch name is passed on as data and no longer echoed (it could carry :: workflow commands).

Why this is safe on pull_request_target: the job checks out nothing and runs nothing from the pull request. It sends four checked fields to .github, whose central workflow already checks out the head commit by sha and validates it as data, as it does for same-repository PRs. The header comment of each shim says this, so a later edit doesn't add a checkout.

Tests

test/workflow-fork-shims.test.ts (22 tests): for each shim, the trigger is pull_request_target and not pull_request; no step uses actions/checkout, git clone/fetch/checkout or ${{ inside run:; the env carries the four fields. The dispatch script is then run in real bash with a stub gh:

  • a fork PR is dispatched with its head sha, ref and number;
  • a push to main (empty PR number) is dispatched;
  • a branch name like $(touch pwned)`touch pwned2`";echo ::add-mask::x is passed through literally, nothing runs, nothing is echoed;
  • a malformed sha, PR number or dataset id exits non-zero before gh is called.

test/workflow-yaml.test.ts, test/workflow-gh-calls.test.ts and test/tree-batched-commit.test.ts still pass (100 tests with the new file). tsc --noEmit -p backend and biome are clean.

Rollout

Dataset repos get the new shims when their CI workflows are redeployed (nemar admin ci sync / the fleet deploy), and their trigger changes only once the new file is on each repo's main. Until then a fork PR's central checks can be run by hand from nemarDatasets/.github (run-bids-validation.yml / run-version-check.yml, workflow_dispatch with dataset_id, ref, head_sha, pr_number).

…idation and version-check

On pull_request GitHub gives a fork's run no secrets, so 'Mint App token' failed
(Input required and not supplied: app-id) and the central check was never
dispatched (nemarDatasets/nm000182#3, nm000232#4, on003825#2).
pull_request_target runs the shim from main with the secrets; the job checks out
and runs nothing from the PR, event fields reach bash through env and are
shape-checked before the dispatch, and the branch name is no longer echoed.
@bruAristimunha

Copy link
Copy Markdown
Contributor Author

The api-test failure is the fork-secrets limit, not this change: the run logs Warning: Test API keys not configured, and every authenticated call returns 401 (POST /auth/login with the admin and user keys, GET /users/me). The tests that do not need a key pass. The change touches only the two shim templates and adds test/workflow-fork-shims.test.ts; lint passes. Rerunning api-test from a branch in nemarOrg should be green.

@bruAristimunha

Copy link
Copy Markdown
Contributor Author

integration-dev failed for the same reason as api-test: it calls the dev API with the test keys, which a fork run does not get. All its failures are authenticated calls (collaborators, DOI/Zenodo admin), and they fail after three attempts. lint, unit-pure, e2e-sandbox and zenodo-sandbox-test pass. The change itself is two workflow templates and one test file; to get green integration runs, push the branch to nemarOrg or rerun the PR with the secrets.

@neuromechanist
neuromechanist merged commit 8138775 into nemarOrg:dev Oct 24, 2026
37 of 39 checks passed
@neuromechanist

Copy link
Copy Markdown
Contributor

Merged, thank you. The change takes effect per dataset repository when the shims are next redeployed; we will follow up with extra test pins and a decision-record note on why pull_request_target is safe here.

This branch was previously deployed

1 inactive deployment
npm — 883768cc Deployed Oct 24, 2026 by neuromechanist via publish #3933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants