Skip to content

Fix pr-merge workflow, HED detection, add bulk CI deploy - #338

Merged
neuromechanist merged 10 commits into
mainfrom
fix/pr-merge-fork-permissions
Apr 4, 2026
Merged

neuromechanist merged 10 commits into
mainfrom
fix/pr-merge-fork-permissions

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Changed pull_request to pull_request_target in the pr-merge workflow template so the GITHUB_TOKEN has write permissions when PRs come from forks
  • Moved attacker-controlled ${{ }} expressions (branch ref, PR number) from inline run to env block to prevent command injection
  • Added --all flag to nemar admin ci add for bulk deployment of CI workflows to all dataset repos
  • Fixed HED annotation detection to include root-level BIDS inheritance events.json files (not just sub-* paths)

Context

Failed run: https://github.com/nemarDatasets/nm000132/actions/runs/23919333754

The PR was from a fork (VisLab/nm000132 -> nemarDatasets/nm000132). GitHub restricts the GITHUB_TOKEN to read-only for fork-originated pull_request events regardless of the permissions block. pull_request_target runs in the base repo's context with full permissions.

Security note

With pull_request_target, actions/checkout@v4 defaults to the base branch (main), not the PR head, so no fork code is executed. The cleanup-staging job's github.event.pull_request.head.ref (attacker-controlled) was moved to the env block to prevent shell injection.

HED detection bug

detectHedAnnotation() filtered for path.startsWith("sub-"), missing root-level events.json files that use BIDS inheritance (e.g. task-flankers_events.json). This caused hedAnnotation=0 on datasets like nm000132 that define HED at the root level.

What was done

  1. Fixed workflow template in backend/src/services/github.ts
  2. Fixed injection vulnerability in cleanup-staging job
  3. Added nemar admin ci add --all for bulk CI deployment
  4. Fixed HED detection in backend/src/services/nemar-sync.ts
  5. Patched all 30 live dataset repos with fixed workflow via GitHub API
  6. Created missed v1.1.0 tag and release on nm000132
  7. Ran manual nemar.org sync for nm000132

Test plan

  • Build passes (bun run build)
  • All tests pass (bun test: 669 pass, 0 fail)
  • CLI help output correct for nemar admin ci add --help
  • All 30 live dataset repos patched and verified
  • Manual nemar.org sync confirmed working for nm000132
  • Next fork PR to a dataset repo should successfully create tag and release
  • After deploy, re-sync nm000132 to verify hedAnnotation=1

Use pull_request_target instead of pull_request so the
GITHUB_TOKEN has write permissions when PRs come from forks.
Fork PRs always get a read-only token with pull_request,
causing tag push and release creation to fail with 403.
@github-actions

github-actions Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR338

Version: 0.7.25-PR338.20aa346
Commit: 20aa346


🤖 Updated on each push.

Move attacker-controlled github.event expressions from
inline run block to env block. With pull_request_target,
the workflow has access to AWS secrets, so a malicious
fork branch name could inject shell commands.
Allows bulk deployment of CI workflows to all dataset repos.
Fetches the dataset list from the API, then deploys to each
sequentially with per-repo progress reporting.

Usage: nemar admin ci add --all [-y]
detectHedAnnotation only checked events.json under sub-*
directories, missing BIDS inheritance files at the root
level (e.g. task-flankers_events.json). This caused
hedAnnotation=0 on datasets like nm000132 that use
root-level HED annotations.
@neuromechanist neuromechanist changed the title Fix pr-merge workflow for fork PRs Fix pr-merge workflow, HED detection, add bulk CI deploy Apr 4, 2026
When the version-doi webhook mints a DOI, trigger a
background nemar.org sync via waitUntil so version updates
appear on the website without manual admin intervention.
- Add console.warn to all empty catch blocks and silent
  .catch() fallbacks in syncToNemarAfterVersionDoi
- Move PR_NUMBER to env block in create-release job
- Log when NEMAR credentials are missing (skip reason)
- Add warning when --all hits 1000 dataset limit
Node 22 ships with npm that already supports OIDC auth.
The npm install -g npm@latest step fails on newer runners
due to missing promise-retry module in Node 22.22.2.
The test was hitting the first dataset from the list endpoint,
which could be a ds/on-prefix dataset without a GitHub repo.
Now filters for nm-prefix datasets and gracefully skips if
the collaborators endpoint returns an error (e.g. auth lacks
access to that specific repo).
@neuromechanist
neuromechanist merged commit eb7cc1d into main Apr 4, 2026
7 checks passed
neuromechanist added a commit that referenced this pull request Apr 17, 2026
Brings to dev from main:
- Maintenance mode middleware (#342)
- MAINTENANCE_MODE=read-only flip (prod only; dev [env.dev.vars] stays off)
- Upload resume fix (#335)
- S3 initremote fix on resume (#337)
- PR-merge workflow, HED detection, bulk CI deploy (#338)
- npm publish fixes (Node 20, npm@11, OIDC)
- GitHub Release auto-tag
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.

1 participant