Skip to content

fix(miner): validate commit SHA format in replay-snapshot path planner (#7796) - #7830

Closed
RealDiligent wants to merge 1 commit into
JSONbored:mainfrom
RealDiligent:fix/replay-snapshot-commit-sha-validation-7796
Closed

fix(miner): validate commit SHA format in replay-snapshot path planner (#7796)#7830
RealDiligent wants to merge 1 commit into
JSONbored:mainfrom
RealDiligent:fix/replay-snapshot-commit-sha-validation-7796

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Summary

  • Add /^[0-9a-f]{7,40}$/i validation to normalizeCommitSha (matching replay-task-generation.ts) so path-traversal-shaped values are rejected before path.join()n- Normalize valid SHAs to lowercase for deterministic snapshot paths
  • Regression test for ../../../../../../tmp/evil-worktree-shaped input; update fixture SHAs across replay-snapshot tests to meet the 7-char minimum

Closes #7796

Test plan

  • npm run typecheck passes locally
  • npm run build:tsc in miner workspace emits matching .js
  • CI validate-code + validate-tests green
  • codecov/patch >= 99% on changed lines

Made with Cursor

@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 21, 2026 14:10
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.54%. Comparing base (1b30e5b) to head (05db29c).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
packages/loopover-miner/lib/replay-snapshot.ts 75.00% 0 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (75.00%) is below the target coverage (99.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7830      +/-   ##
==========================================
- Coverage   88.65%   88.54%   -0.11%     
==========================================
  Files         730       89     -641     
  Lines       76959    21318   -55641     
  Branches    22789     3698   -19091     
==========================================
- Hits        68229    18877   -49352     
+ Misses       7684     2256    -5428     
+ Partials     1046      185     -861     
Flag Coverage Δ
shard-1 ?
shard-2 26.92% <75.00%> (-24.61%) ⬇️
shard-3 7.69% <25.00%> (-42.55%) ⬇️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/replay-snapshot.ts 26.92% <75.00%> (-73.08%) ⬇️

... and 641 files with indirect coverage changes

@RealDiligent
RealDiligent force-pushed the fix/replay-snapshot-commit-sha-validation-7796 branch from 05db29c to 8f1c468 Compare July 21, 2026 14:18
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 21, 2026
@loopover-orb

loopover-orb Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-21 14:27:12 UTC

4 files · 1 AI reviewer · no blockers · CI pending · dirty

⏸️ Suggested Action - Manual Review

Review summary
Adds the same 7-40 hex-char SHA regex used in replay-task-generation.ts to normalizeCommitSha in replay-snapshot.ts, closing the path-traversal gap where a crafted commitSha like `../../../../../../tmp/evil-worktree` reached path.join() unchecked. The fix is applied at the correct source layer (the normalize function itself, before the value is ever used to build a path), lowercasing valid SHAs for deterministic snapshot paths, and the regression test asserts the traversal-shaped input throws. Fixture SHAs across the test files are bumped to 7+ hex chars to satisfy the new minimum, which is mechanical and consistent with the new validation.

Nits — 5 non-blocking
  • codecov/patch is at 75% on changed lines — the compiled replay-snapshot.js is counted as diff surface but isn't part of src/**, and the .ts hunk itself is small, so double-check which uncovered branches the tool is flagging (e.g., a SHA between 40-hex boundary or an empty-after-trim case) and add a case if it's a real gap in replay-snapshot.ts.
  • validate-tests (1) failed with no detail provided; per BASE BRANCH STATUS this branch is 6 commits behind default, which is a plausible cause worth ruling out with a rebase before treating it as a defect in this diff.
  • The compiled replay-snapshot.js diff is generated output mirroring the .ts change 1:1 — fine, but worth confirming the build step is what produced it rather than a hand-edit, since hand-edited generated files tend to drift.
  • Add a boundary-length test (39 vs 41 hex chars) if not already covered, since the regex's {7,40} bound is exactly the kind of off-by-one branch codecov's branch-counting would want exercised.
  • Consider whether normalizeRepoFullName has a similar unchecked-value-into-path-join risk worth a follow-up issue, given this PR already found one path-traversal gap in a sibling normalizer.

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 #7796
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: 395 registered-repo PR(s), 185 merged, 36 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 395 PR(s), 36 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds the exact /^[0-9a-f]{7,40}$/i validator to normalizeCommitSha in replay-snapshot.ts, rejecting non-hex/path-traversal-shaped values before path.join, and includes a regression test using the exact '../../../../../../tmp/evil-worktree' example from the issue plus updated fixture SHAs.

Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, JavaScript, Ruby, Svelte, TypeScript, Markdown, MDX
  • Official Gittensor activity: 395 PR(s), 36 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
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 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (conflicts with the base branch — resolve and open a fresh PR). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

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.

replay-snapshot.ts's normalizeCommitSha has no format validation, letting a crafted value escape the intended snapshot directory via path.join

1 participant