Repository navigation
fix(dependency-gate): compare against the merge base, not the base branch tip - #4
Merged
Merged
Conversation
…anch tip `github.event.pull_request.base.sha` is the tip of the base branch at event time, not the merge base. Diffing a pull request's lockfile against the tip replays every base-branch commit made since the branch forked, inverted: what the base branch dropped reads as something the pull request added. A branch that is merely behind gets findings for packages it never touched, and the only way through is a `deps-reviewed` label signing off on nothing real. velocity-v1#511 hit this. It changes no `bun.lock`, but was five commits behind master, and master had re-resolved the tree: `@types/protobufjs` disappeared from the lockfile and the hoisted `@velocity-exchange/common/@velocity-exchange/sdk` entry collapsed. Against the tip those two read as "new package" and "source changed". Running the parser over the real blobs reproduces the run's findings and its digest exactly with base = tip, and reports nothing with base = merge base. Resolve the merge base through the compare API rather than `git merge-base`. The head commit is not in the checkout on a fork pull request -- actions/checkout fetches refs/heads/* and refs/tags/* of the base repository only -- so `git merge-base` would fail exactly where the gate matters most. The API needs nothing fetched and only the `contents: read` the action already requires. The merge base is an ancestor of base.sha, so it is still base-branch content: the "never trust pull request content" invariant is unchanged. The existing tip candidates stay on as fallbacks behind it, so a shallow checkout or a rewritten base degrades to the old over-reporting behaviour instead of failing the run. Both `prt` and `pr` modes had the bug and both are fixed.
ChesterSim
requested review from
0xahzam,
ChewingGlass,
csadminlc,
jt-lumen and
noah-velocity-admin
as code owners
September 15, 2026 06:11
…the API call
Review found that the previous commit was right for `prt` and wrong for `pr`.
The two modes read the head lockfiles from different places. `prt` reads them
through the contents API at `HEAD_SHA`, a real commit on the pull request's
branch, so the merge base is the correct other side. `pr` reads them off the
workspace, which under `pull_request` is GitHub's merge commit
(`refs/pull/N/merge`, "Merge <head> into <base tip>"). That tree already carries
the base branch through `base.sha`, so comparing it to the merge base attributes
the base branch's own dependency changes to the pull request -- the same class of
false finding this branch set out to remove, in the opposite direction.
`pr` mode never had the bug for that reason, and is restored to `BASE_SHA`.
Also harden the helper, both from the same review:
- Validate the compare API's answer with the same regex as its inputs. `gh api`
writes its error body to *stdout* and exits 1, and `--jq` yields "null" for a
missing field, so `mb` could hold a non-empty non-SHA and the `${mb:-}` guard
would never fire. `git rev-parse --verify --quiet` rejected those anyway, so
this changes no behaviour; it stops the one externally-sourced string in the
file reaching git unchecked.
- Warn when the API call fails instead of degrading silently. The fallback still
gates, but it over-reports on a branch that is behind, and over-reporting
changes the digest, which deletes a sign-off label that was correctly applied.
A network blip should not do that without saying so.
Document the residual behaviour change under "Known limits": a package the target
branch removed after the fork point, which the branch still carries, is no longer
reported. That is what makes the gate agree with the three-dot diff a reviewer
reads, and the removal wins on merge in any case.
jt-lumen
approved these changes
Sep 15, 2026
ChesterSim
added a commit
to velocity-exchange/velocity-v1
that referenced
this pull request
Sep 15, 2026
Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4
ChesterSim
added a commit
to velocity-exchange/velocity-docs
that referenced
this pull request
Sep 15, 2026
Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4
ChesterSim
added a commit
to velocity-exchange/velocity-common
that referenced
this pull request
Sep 15, 2026
Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4
This was referenced Sep 15, 2026
ChesterSim
added a commit
to velocity-exchange/velocity-docs
that referenced
this pull request
Sep 15, 2026
Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4
ChesterSim
added a commit
to velocity-exchange/velocity-v1
that referenced
this pull request
Sep 15, 2026
Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4
ChesterSim
added a commit
to velocity-exchange/velocity-common
that referenced
this pull request
Sep 15, 2026
Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4
ChesterSim
added a commit
to velocity-exchange/velocity-docs
that referenced
this pull request
Nov 3, 2026
* chore: refresh Velocity branding (#126) * chore: refresh Velocity branding * fix: use dark logo on docs mobile * fix: prevent duplicate docs logo * fix: enforce docs logo breakpoints * refactor: simplify logo component structure and improve breakpoint handling --------- Co-authored-by: csadminlc <chestersimadmin@lumencollective.xyz> Co-authored-by: Noah Prince <chewinglass123@gmail.com> Co-authored-by: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Co-authored-by: 0xahzam <104062587+0xahzam@users.noreply.github.com> * chore(ci): update dependency-gate to v2.0.1 (#132) Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4 * docs: pause bug bounty payouts during audit (#135) Adds a banner to the bug bounty page saying no bounties are paid while an audit is in progress. Reports are still accepted at the security address. --------- Co-authored-by: csadminlc <chestersimadmin@lumencollective.xyz> Co-authored-by: Noah Prince <chewinglass123@gmail.com> Co-authored-by: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Co-authored-by: 0xahzam <104062587+0xahzam@users.noreply.github.com>
ChesterSim
added a commit
to velocity-exchange/velocity-docs
that referenced
this pull request
Nov 6, 2026
* chore: refresh Velocity branding (#126) * chore: refresh Velocity branding * fix: use dark logo on docs mobile * fix: prevent duplicate docs logo * fix: enforce docs logo breakpoints * refactor: simplify logo component structure and improve breakpoint handling --------- Co-authored-by: csadminlc <chestersimadmin@lumencollective.xyz> Co-authored-by: Noah Prince <chewinglass123@gmail.com> Co-authored-by: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Co-authored-by: 0xahzam <104062587+0xahzam@users.noreply.github.com> * chore(ci): update dependency-gate to v2.0.1 (#132) Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4 * docs: pause bug bounty payouts during audit (#135) Adds a banner to the bug bounty page saying no bounties are paid while an audit is in progress. Reports are still accepted at the security address. * docs: remove Velocity Vaults from the developer docs (#137) Drop the vault-managers and vault-depositors sections, the vaults program address, and the vaults-sdk and vaults program references. Spot-market and insurance-fund vault wording is unchanged. --------- Co-authored-by: csadminlc <chestersimadmin@lumencollective.xyz> Co-authored-by: Noah Prince <chewinglass123@gmail.com> Co-authored-by: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Co-authored-by: 0xahzam <104062587+0xahzam@users.noreply.github.com>
ChesterSim
added a commit
to velocity-exchange/velocity-docs
that referenced
this pull request
Nov 17, 2026
* chore: refresh Velocity branding (#126) * chore: refresh Velocity branding * fix: use dark logo on docs mobile * fix: prevent duplicate docs logo * fix: enforce docs logo breakpoints * refactor: simplify logo component structure and improve breakpoint handling --------- Co-authored-by: csadminlc <chestersimadmin@lumencollective.xyz> Co-authored-by: Noah Prince <chewinglass123@gmail.com> Co-authored-by: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Co-authored-by: 0xahzam <104062587+0xahzam@users.noreply.github.com> * chore(ci): update dependency-gate to v2.0.1 (#132) Picks up the merge-base fix. The gate compared each pull request against the base branch tip rather than the merge base, so a branch that was merely behind got findings for dependencies it never touched, and the only way through was a deps-reviewed label signing off on nothing real. velocity-exchange/shared-workflows#4 * docs: pause bug bounty payouts during audit (#135) Adds a banner to the bug bounty page saying no bounties are paid while an audit is in progress. Reports are still accepted at the security address. * docs: remove Velocity Vaults from the developer docs (#137) Drop the vault-managers and vault-depositors sections, the vaults program address, and the vaults-sdk and vaults program references. Spot-market and insurance-fund vault wording is unchanged. * docs: replace Terms of Use with updated July 2026 text (#139) --------- Co-authored-by: csadminlc <chestersimadmin@lumencollective.xyz> Co-authored-by: Noah Prince <chewinglass123@gmail.com> Co-authored-by: Noah Prince <83885631+ChewingGlass@users.noreply.github.com> Co-authored-by: 0xahzam <104062587+0xahzam@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
github.event.pull_request.base.shais the tip of the base branch at event time, not the merge base. Underpull_request_targetthe action reads the head lockfiles through the contents API atHEAD_SHA(a real commit on the PR's branch) and diffs them against that tip:So a pull request that is merely behind its base branch gets the base branch's own lockfile history replayed at it, inverted: an entry the base branch dropped is still present at head, and reads as one the pull request added. The author's only way through is a
deps-reviewedlabel signing off on findings that do not exist.How it showed up
velocity-v1#511 failed the gate (run) with two
bun.lockfindings:@types/protobufjs@velocity-exchange/sdkThat PR touches no
bun.lockat all. Its files are.changeset/,packages/cli-admin/,packages/sdk/src/adminClient.ts,rust/Cargo.lock.It was 5 commits behind master, and master had re-resolved the tree in the meantime (
@velocity-exchange/common0.0.1 to 0.10.1). That dropped@types/protobufjsfrom the lockfile and collapsed the hoisted@velocity-exchange/common/@velocity-exchange/sdkentry from 66 nested keys to 4. The stale branch still carried both, so against master's tip they read as additions.git diff <merge-base> <head> -- bun.lockis emptygit diff <base tip> <head> -- bun.lockis 137 insertions, 11 deletionsVerified, not assumed
Running
lockfile_packages.pyover the real git blobs:The first case reproduces the failing run's findings and its digest
767947ca9e2ca444745af84fbyte for byte. The second is clean. The job log confirms the base used:Mode prt, comparing against af1792c65a9c0a6557bc709f53f5a7741c53beae.The fix
prtmode only. Resolve the merge base through the compare API, notgit merge-base.git merge-baseis the obvious move and it is wrong here. On a fork pull request the head commit is not an object in the checkout at all:actions/checkoutfetchesrefs/heads/*andrefs/tags/*of the base repository only, norefs/pull/*.git merge-basewould exit non-zero and take the step down with it, or fall through to the hardCould not resolve the base revisionerror, so the gate would become unrunnable on exactly the pull requests it matters most for. velocity-v1#511 would have worked by luck, its head branch lives in the base repo.repos/{repo}/compare/{base}...{head}needs nothing fetched and only thecontents: readthe action already requires.Security is unchanged: the merge base is by definition an ancestor of
base.sha, so it is still base-branch content. Nothing of the pull request's is read or executed. An attacker can only make the merge base older, which yields more findings, never fewer.The old tip candidates stay on as fallbacks behind the merge base, so a shallow checkout, a rewritten base, or an API blip degrades to the old over-reporting rather than failing the run. That degradation now emits a
::warning::, because over-reporting changes the digest, which deletes a correctly-applied sign-off label.prmode deliberately keeps the base tipThe first commit changed both modes. That was wrong, and review caught it.
The two modes read the head lockfiles from different places.
prtreads them atHEAD_SHA.prreads them off the workspace, which underpull_requestis GitHub's merge commit, confirmed in this PR's own CI:git checkout --progress --force refs/remotes/pull/4/merge->HEAD is now at 58f2898 Merge 36082f9 into d22dd026. That tree already carries the base branch throughbase.sha, so comparing it to the merge base would attribute the base branch's own changes to the PR, the same class of false finding in the opposite direction.prmode never had the original bug for that reason, and is restored toBASE_SHA.other(push) mode is untouched and never reaches the helper.Checks
test_parser.py(105 assertions), theaction.ymlcontract check, andshellcheck --severity=warningall pass locally. Both helper paths were exercised against the live API: the happy path returns the merge base, and a 404 warns, rejectsgh's error body (which it writes to stdout), and falls back to the tip.Known gap: no regression test
The
dogfood-pr/dogfood-prtjobs point attests/fixtures/stable/*, which by design never change, so they cannot catch a stale-base inversion in either direction. That is precisely why the first commit'spr-mode regression passed CI green. A real test needs a fixture repository with a deliberately-behind branch; that is infrastructure rather than a line of Python, so it is not in this PR. The failure mode is loud (the gate over-reports and blocks a PR) rather than silent, which bounds the cost.Follow-ups, not in this PR
velocity-exchange/dependency-gate's default branch carries the same bug and its newest tag isv2.0.0. This repo's absorbed copy is now ahead of it.velocity-exchange/dependency-gate@e039f99f(v2.0.0). It needs repointing at this copy, or the standalone repo needs the same fix and av2.0.1.dependency-gate/README.md:55and:83still tell consumersuses: velocity-exchange/dependency-gate@v2, which is no longer where this copy lives.README.md:297-298cites.github/workflows/dependency-gate.ymlandtests/fixtures/Cargo.lock; the real paths aredependency-gate-selfgate.ymlanddependency-gate/tests/fixtures/Cargo.lock. Same stale reference atdependency-gate-test.yml:107. Left alone because the rightuses:line depends on follow-up 2.deps-reviewedwould be signing off on nothing.