Skip to content

fix(review): correlate cross-hunk lockfile tamper signals by package (#8351)#8491

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
milosde111:fix/lockfile-tamper-cross-hunk-correlation-8351
Jul 24, 2026
Merged

fix(review): correlate cross-hunk lockfile tamper signals by package (#8351)#8491
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
milosde111:fix/lockfile-tamper-cross-hunk-correlation-8351

Conversation

@milosde111

Copy link
Copy Markdown
Contributor

Summary

  • scanPackageLockPatch now keys header-less (unattributed) fallback buckets by package name recovered from nearby npm-registry resolved URLs — including unchanged context lines — so a legitimate version bump and its resolved/integrity change that land in separate hunks (split by a depth-0 }) merge into one candidate instead of false-flagging.
  • When no package name is recoverable, the existing per-block #unattributed-N sequence is preserved; two different recoverable packages never share a bucket.
  • Finding display text for header-less hunks still uses (unattributed lockfile entry) so the Lockfile tamper detector can be silently evaded by placing the changed field outside the entry header's diff-context window #7778 assertions stay unchanged.
  • Regression tests: legitimate cross-hunk version+integrity bump → no finding; genuine cross-hunk tamper (integrity/resolved without version bump) → still flags; plus scoped-package, distinct-package, and sequence→package upgrade/merge cases for branch coverage.

Closes #8351

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • Ran targeted vitest + coverage on src/review/lockfile-tamper.ts (100% branch). Full npm run test:ci not run on this Windows host (npm ci blocked by platform-only @codecov/bundle-analyzer); run the full local gate before push.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

UI Evidence

N/A — backend review-path fix only.

Notes

  • Direction: package-name-keyed unattributed buckets via packageNameFromResolvedUrl, with sequence-key fallback and in-block promote/merge when a resolved URL appears after a sequence key was minted.

…oss hunk boundaries

Introduces a new function to recover package names from resolved URLs, allowing for better correlation of version and integrity changes across separate hunks. This change addresses issues where legitimate version bumps could be falsely flagged due to the split of entries in the lockfile. Additionally, several regression tests have been added to ensure correct behavior in various scenarios involving unattributed entries, including cases where package names are inferred from resolved URLs. This implementation aims to improve the accuracy of lockfile tamper detection and maintain the integrity of package management processes. Closes JSONbored#8351.
@milosde111
milosde111 requested a review from JSONbored as a code owner July 24, 2026 15:23
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (14ad838) to head (6ad7def).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8491      +/-   ##
==========================================
+ Coverage   79.69%   89.65%   +9.95%     
==========================================
  Files         791       98     -693     
  Lines       79334    22852   -56482     
  Branches    23960     3916   -20044     
==========================================
- Hits        63222    20487   -42735     
+ Misses      13047     2187   -10860     
+ Partials     3065      178    -2887     
Flag Coverage Δ
shard-1 100.00% <100.00%> (+44.58%) ⬆️
shard-2 2.73% <0.00%> (-46.25%) ⬇️
shard-3 2.73% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/review/lockfile-tamper.ts 100.00% <100.00%> (ø)

... and 693 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 24, 2026
@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-24 15:41:49 UTC

2 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This fix reworks the unattributed-lockfile fallback keying in scanPackageLockPatch so that a package name recovered from a nearby npm-registry `resolved` URL (context or changed lines) is used to key the fallback bucket, letting version and resolved/integrity signals for the same package correlate across hunks split by a depth-0 `}` instead of each hunk minting its own `#unattributed-N` sequence key. I traced several of the trickier merge scenarios (sequence→package promotion with and without a prior package-keyed candidate, off-registry URL merge via the `??` left-arm) by hand against the code and the outcomes match the new tests exactly — the logic is sound and the tests exercise real reachable states, not fabricated ones. The display label `(unattributed lockfile entry)` is correctly preserved for #7778 compatibility even though the internal Map key is now package-qualified.

Nits — 5 non-blocking
  • src/review/lockfile-tamper.ts:54 — packageNameFromResolvedUrl hardcodes `https:​//registry.npmjs.org/` again instead of reusing NPM_REGISTRY_HOST_RE; consider deriving both from one source of truth to avoid future drift.
  • packageNameFromResolvedUrl only recognizes `https:​//registry.npmjs.org/...` URLs, so an unattributed block whose only recoverable identity signal is a non-https scheme (e.g. `git+ssh:​//`) still falls back to per-block sequence keys — worth a comment noting this is an intentional scope limit, not an oversight.
  • The `#unattributed-` vs `#unattributed:` substring check in promoteSequenceKeyToPackage (lockfile-tamper.ts:176) is a bit fragile-looking (relies on `-` vs `:` never colliding with a package name); a small helper or explicit prefix constant would make the distinction more self-evident.
  • Consider extracting the `registry.npmjs.org` host constant so NPM_REGISTRY_HOST_RE and packageNameFromResolvedUrl can't drift independently.
  • A short doc-comment example (one concrete before/after JSON snippet) alongside packageNameFromResolvedUrl would make the recovery mechanism easier to spot-check in future reviews.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8351
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 238 registered-repo PR(s), 161 merged, 9 issue(s).
Contributor context ✅ Confirmed Gittensor contributor milosde111; Gittensor profile; 238 PR(s), 9 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: significant
Linked issue satisfaction

Addressed
The diff implements package-name-recovered fallback keying (via packageNameFromResolvedUrl and promoteSequenceKeyToPackage) to correlate unattributed version/resolved/integrity signals across hunk boundaries for the same package, and adds the exact regression tests the issue requested: a false-positive-suppression test for a legitimate cross-hunk version+integrity bump and a true-positive test for

Review context
  • Author: milosde111
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, TypeScript, Cuda, HTML, MDX, Python, Rust
  • Official Gittensor activity: 238 PR(s), 9 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 7480c78 into JSONbored:main Jul 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(review): lockfile-tamper-risk scanner loses cross-hunk version/integrity correlation, causing false positives

1 participant