Repository navigation
fix(ci): vet the adhoc build ref before running it with release secrets - #12161
Conversation
The adhoc workflow checked out any requested ref and ran its scripts and electron-builder config with MAC_CERTS, the notary password, and the adhoc publisher token in reach — including refs/pull/* fork code a maintainer could dispatch in one innocuous-looking click. Vet the ref before checkout: PR refs are refused, branches/tags resolve in a bare tree:0 scratch fetch, raw SHAs must be reachable from a repo branch or tag (a partial clone lazily serves PR-only commits by SHA, so name resolution alone is not a trust test), and checkout pins the vetted SHA so a race push cannot swap the commit. Also reference an adhoc-mac-build environment so the secrets can later be fenced off from stale workflow copies via repo settings.
📝 WalkthroughWalkthroughThe workflow documents repository ref restrictions and rejects pull-request refs. It assigns the build job to the 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e3c70036-ca02-4715-b14f-e8349f521baf
📒 Files selected for processing (1)
.github/workflows/adhoc-mac-build.yml
| # Why an environment: it gives the signing/notary/App secrets somewhere to | ||
| # live that a stale copy of this workflow on an old branch cannot reach. | ||
| # Referencing it is a no-op until repo settings give it teeth; the intended | ||
| # follow-up is to move MAC_CERTS, MAC_CERTS_PASSWORD, APPLE_ID, | ||
| # APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID, HOURLY_RELEASE_APP_ID, and | ||
| # HOURLY_RELEASE_APP_PRIVATE_KEY into it, then pin its deployment branch | ||
| # policy to main so only main's copy of this file can read them. | ||
| environment: adhoc-mac-build |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
repo="stablyai/orca"
environment="adhoc-mac-build"
echo "Environment configuration:"
gh api "repos/$repo/environments/$environment"
echo "Environment deployment branch policies:"
gh api "repos/$repo/environments/$environment/deployment-branch-policies" || true
echo "Repository secret names:"
gh secret list --repo "$repo"
echo "Environment secret names:"
gh secret list --repo "$repo" --env "$environment"Repository: stablyai/orca
Length of output: 336
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Workflow references:"
rg -n "adhoc-mac-build|MAC_CERTS|MAC_CERTS_PASSWORD|APPLE_ID|APPLE_APP_SPECIFIC_PASSWORD|APPLE_TEAM_ID|HOURLY_RELEASE_APP_ID|HOURLY_RELEASE_APP_PRIVATE_KEY|environment:" .github/workflows/adhoc-mac-build.yml .github/workflows || true
echo
echo "Repository secret names:"
gh secret list --repo "stablyai/orca" || true
echo
echo "Files mentioning environment references:"
rg -n "environment:\\s*adhoc-mac-build|secrets:\\s*\\n?\\s*[A-Z0-9_.]+" .github/workflows || true
echo
echo "Workflow status/stat excerpt if available:"
git ls-files .github/workflows/adhoc-mac-build.yml
wc -l .github/workflows/adhoc-mac-build.yml
sed -n '70,105p' .github/workflows/adhoc-mac-build.ymlRepository: stablyai/orca
Length of output: 9578
Complete the environment secret migration before relying on this control.
The adhoc-mac-build environment does not restrict secrets.* usage, and the workflow still reads signing/App/release keys from repository-level secrets. Move those secrets into adhoc-mac-build, remove the repository-level copies, and pin the environment deployment policy to main before treating this workflow as protected.
Greptile SummaryThis PR hardens the ad-hoc macOS build workflow by introducing a ref-vetting step that runs before checkout and before any signing secrets are in scope. The fix directly addresses a previously identified issue where dispatching a fork PR ref could run unreviewed code against
Confidence Score: 4/5Safe to merge; the core vetting logic is correct and closes the fork-code-with-signing-credentials path, but the environment declaration is a no-op until an admin migrates secrets and sets branch policies The ref vetting, reachability check, and SHA pinning are all implemented correctly and the test matrix in the PR description covers the key bypass attempts including the partial-clone/lazy-fetch edge case. The minor gap is the third rev-parse candidate lacking a Files Needing Attention: .github/workflows/adhoc-mac-build.yml — specifically the vet step loop and the environment declaration
|
| Filename | Overview |
|---|---|
| .github/workflows/adhoc-mac-build.yml | Adds a ref-vetting step before checkout that blocks PR refs outright and verifies branch/tag reachability for raw SHAs; pins the vetted SHA at checkout to close the TOCTOU window; adds an environment reference as a no-op placeholder for future secret isolation |
Sequence Diagram
sequenceDiagram
participant Operator
participant GHA as GitHub Actions
participant VetStep as Vet the requested ref
participant GitHub as github.com/stablyai/orca
participant Checkout as actions/checkout
Operator->>GHA: workflow_dispatch(ref, label)
GHA->>VetStep: "REQUESTED_REF = inputs.ref || github.ref_name"
VetStep->>VetStep: "case match refs/pull/* or pull/*?"
alt PR ref detected
VetStep-->>GHA: exit 1 (refused)
else non-PR ref
VetStep->>GitHub: "git init bare + fetch --filter=tree:0 refs/heads/* refs/tags/*"
GitHub-->>VetStep: commit graph (no trees/blobs)
VetStep->>VetStep: rev-parse: try refs/heads/REF then refs/tags/REF then REF
alt resolves to a SHA
VetStep->>VetStep: for-each-ref --contains SHA refs/heads refs/tags
alt SHA reachable from branch or tag
VetStep-->>GHA: "output sha=pinned SHA"
GHA->>Checkout: "ref = steps.vetted.outputs.sha"
Checkout->>GitHub: clone at pinned SHA
GitHub-->>Checkout: source tree
Checkout-->>GHA: workspace ready
GHA->>GHA: run build with MAC_CERTS + notary secrets
else SHA not reachable (fork/PR-only commit)
VetStep-->>GHA: exit 1 (not reachable from any branch or tag)
end
else does not resolve
VetStep-->>GHA: exit 1 (does not resolve)
end
end
Reviews (1): Last reviewed commit: "fix(ci): vet the adhoc build ref before ..." | Re-trigger Greptile
| for cand in "refs/heads/$REQUESTED_REF" "refs/tags/$REQUESTED_REF" "$REQUESTED_REF"; do | ||
| if sha="$(git -C "$scratch" rev-parse --verify --quiet "$cand^{commit}")"; then | ||
| break | ||
| fi | ||
| sha="" | ||
| done |
There was a problem hiding this comment.
Third rev-parse candidate lacks
-- separator
The third loop candidate passes $REQUESTED_REF directly to git rev-parse without a -- end-of-options separator. If an operator types a value like -foo or --help in the dispatch UI, git receives rev-parse --verify --quiet --help^{commit}, treating it as an unknown option instead of a refspec. In practice this still results in a failed resolution and a rejected ref — so there is no security bypass — but the error message from git will be cryptic ("unknown option") rather than the clearer workflow-level message. The first two candidates are safe because the refs/heads/ and refs/tags/ prefixes prevent any --leading value from being parsed as a flag.
Replacing the bare candidate with -- "$REQUESTED_REF^{commit}" (after inserting -- before the argument in the rev-parse call for all three candidates) would both eliminate the confusion and signal the intent that the argument is always a refspec, never an option.
| # APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID, HOURLY_RELEASE_APP_ID, and | ||
| # HOURLY_RELEASE_APP_PRIVATE_KEY into it, then pin its deployment branch | ||
| # policy to main so only main's copy of this file can read them. | ||
| environment: adhoc-mac-build |
There was a problem hiding this comment.
environment: adhoc-mac-build is a no-op until the environment is created and secrets migrated
Referencing a GitHub environment that has not yet been created with protection rules provides no isolation today. If the environment does not exist in repo settings, GitHub will resolve it implicitly with no branch policy and no secret scope restriction, meaning the seven signing/notary/App secrets remain readable by any workflow run — including stale copies of this file on old branches — just as before. The inline comment documents this correctly, but the gap is worth calling out explicitly: the protection this declaration is intended to enforce becomes active only after an admin creates the adhoc-mac-build environment, moves the secrets into it, and sets its deployment branch policy to main. Until then, the environment: line is advisory documentation rather than a control.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…ts (stablyai#12161) The adhoc workflow checked out any requested ref and ran its scripts and electron-builder config with MAC_CERTS, the notary password, and the adhoc publisher token in reach — including refs/pull/* fork code a maintainer could dispatch in one innocuous-looking click. Vet the ref before checkout: PR refs are refused, branches/tags resolve in a bare tree:0 scratch fetch, raw SHAs must be reachable from a repo branch or tag (a partial clone lazily serves PR-only commits by SHA, so name resolution alone is not a trust test), and checkout pins the vetted SHA so a race push cannot swap the commit. Also reference an adhoc-mac-build environment so the secrets can later be fenced off from stale workflow copies via repo settings.
Summary
Hardens the adhoc macOS build workflow (added in #12051) against the P1 flagged by the v1.4.165-rc.0 prod release scan: the workflow checked out any requested ref and ran that ref's scripts (
verify-macos-release-env.mjs,ensure-native-runtime.mjs,electron-builder.config.cjs) withMAC_CERTS, the notary app-specific password, and the adhoc publisher token in reach. Dispatching a fork PR ref ("just build that community PR") would hand fork code the release signing identity.Changes, all in
.github/workflows/adhoc-mac-build.yml:refs/pull/*/pull/*refs are refused outright.tree:0scratch fetch of the repo's heads and tags (annotated tags peel to their commit).adhoc-mac-buildenvironment. This is a no-op until repo settings give it teeth; the intended follow-up (admin-only) is to move the 7 signing/notary/App secrets into it and pin its deployment branch policy tomain, which fences stale copies of this workflow on old branches away from the secrets entirely.Trust model note: a vetted branch always belongs to someone with write access — the same trust the dispatch button already requires. This PR removes the escalation from "can dispatch a build" to "can run unreviewed fork code with signing credentials".
Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildThe four package commands don't exercise workflow YAML; instead the vetting script was extracted from the YAML (parse-validated) and run locally against the real
stablyai/orcaremote across 9 cases:main8c5371ebad(current main head)refs/heads/mainv1.4.164(annotated tag)9cea094620(peeled commit, not the tag object)8c5371ebad(short SHA on main)pull/12137/headrefs/pull/12137/mergetotally-made-up-branch-xyzdeadbeef…(alien SHA)94d88dbc60e1…, exists only behindrefs/pull/*)AI Review Report
Reviewed as part of the v1.4.164..v1.4.165-rc.0 prod release scan (7 orchestrated reviewers; the security and release/package workers independently converged on this finding). Risks checked for this fix: ref-name ambiguity (branch vs tag tie-break kept branch-first to match
actions/checkoutbehavior; exact-name resolution avoids ls-remote tail-glob mismatches), TOCTOU between vet and checkout (closed by pinning the SHA), shell injection (untrusted values enter only viaenv:, per the file's existing zizmor conventions), and lazy promisor fetch resurrecting the fork-SHA hole (closed by the reachability check). Cross-platform: CI-only change, runs on the macOS runner's bash + git ≥2.20 (--filter=tree:0,for-each-ref --containsneed 2.20/2.7); no app code, shortcuts, paths, or Electron surface touched.Security Audit
This PR is itself the security fix for the release-scan P1. Input handling:
inputs.refandinputs.labelreach shell only throughenv:vars in quoted expansions (unchanged pattern). Command execution: the new step runs onlygitwith argv arrays againsthttps://github.com/${{ github.repository }}. Secrets: no new secret exposure; the step runs before any secret-bearing step. Residual risk, explicitly out of scope here and needing repo admin: (1) create/protect theadhoc-mac-buildenvironment, moveMAC_CERTS,MAC_CERTS_PASSWORD,APPLE_ID,APPLE_APP_SPECIFIC_PASSWORD,APPLE_TEAM_ID,HOURLY_RELEASE_APP_ID,HOURLY_RELEASE_APP_PRIVATE_KEYinto it, delete the repo-level copies, and set its deployment branch policy tomain; until then a stale workflow copy on an old branch can still read repo-level secrets. (2) A vetted repo branch still runs its own lockfile/postinstall and electron-builder config with signing env — inherent to "sign someone's branch"; the environment policy plus write-access trust is the accepted boundary. (3) Repo-wide SHA-pinning of third-party actions (nick-fields/retry,pnpm/action-setup) is a separate consistent follow-up; this file matches house tag-pin style for now.Notes
Post-Merge Action Items (repo admin — this PR alone does not finish the fix)
adhoc-mac-buildenvironment (auto-created on first dispatch, or create it under Settings → Environments): set deployment branch policy tomainonly. This is what actually fences stale copies of this workflow on old branches; until then theenvironment:line is advisory.MAC_CERTS,MAC_CERTS_PASSWORD,APPLE_ID,APPLE_APP_SPECIFIC_PASSWORD,APPLE_TEAM_ID,HOURLY_RELEASE_APP_ID,HOURLY_RELEASE_APP_PRIVATE_KEY. Requires the secret values, so admin-only.hourly-mac-build.ymlreads the same repo-level secrets and will break the moment they're deleted. Either give the hourly workflow its own environment first (separate PR, ask if wanted) and copy the secrets into both, or skip the deletion and keep only the branch-policy/reviewer gate — accepting that stale workflow copies can still read repo-level secrets.nick-fields/retry,pnpm/action-setup) across all workflows; house style is currently tag pins everywhere, so it should be done consistently rather than just here.