Skip to content

fix(miner): reject non-hex commitSha in replay-snapshot path planner - #7891

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

fix(miner): reject non-hex commitSha in replay-snapshot path planner#7891
bohdansolovie wants to merge 1 commit into
JSONbored:mainfrom
bohdansolovie:fix/replay-snapshot-commit-sha-7796

Conversation

@bohdansolovie

Copy link
Copy Markdown
Contributor

Summary

  • Harden normalizeCommitSha with /^[0-9a-f]{7,40}$/i (same guard as replay-task-generation.ts) and lowercase the accepted value.
  • Path-traversal / non-hex / too-short SHAs are rejected before path.join.
  • Update fixtures to 7+ hex chars and add regression coverage for traversal, format rejects, and case normalization.

Closes #7796

Test plan

  • vitest run test/unit/miner-replay-snapshot.test.ts
  • Local coverage hits on the new guard lines
  • CI green (changes, validate-code, validate-tests, validate-tests-merge, codecov/patch)

Made with Cursor

Reuse the same /^[0-9a-f]{7,40}$/i guard as replay-task-generation so a
path-traversal-shaped commitSha cannot escape .loopover-replay-snapshots.

Closes JSONbored#7796
@bohdansolovie
bohdansolovie requested a review from JSONbored as a code owner July 21, 2026 16:14
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 21, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@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 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.41%. Comparing base (e7e10e7) to head (a13eb65).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/loopover-miner/lib/replay-snapshot.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7891      +/-   ##
==========================================
- Coverage   91.39%   88.41%   -2.99%     
==========================================
  Files         730       89     -641     
  Lines       74774    21318   -53456     
  Branches    22818     3698   -19120     
==========================================
- Hits        68343    18849   -49494     
+ Misses       5389     2291    -3098     
+ Partials     1042      178     -864     
Flag Coverage Δ
shard-1 0.00% <0.00%> (-58.57%) ⬇️
shard-2 0.00% <0.00%> (-51.85%) ⬇️
shard-3 0.00% <0.00%> (-50.22%) ⬇️

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 0.00% <0.00%> (-100.00%) ⬇️

... and 641 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 21, 2026
@loopover-orb

loopover-orb Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Caution

🛑 LoopOver review result - fixes required

Review updated: 2026-07-21 16:26:20 UTC

2 files · 1 AI reviewer · no blockers · CI failing · unstable

🛑 Suggested Action - Fix Blockers

Review summary
This is a narrow, well-targeted security fix: it hardens `normalizeCommitSha` in `replay-snapshot.ts` with the same `/^[0-9a-f]{7,40}$/i` pattern already used in `replay-task-generation.ts`, rejecting path-traversal/non-hex/too-short SHAs before `path.join` in `planReplaySnapshotPath`, and lowercases the accepted value for stable caching. The change is applied consistently across the module — `normalizeCommitSha` is the single choke point used by `planReplaySnapshotPath`, `exportReplaySnapshot`, `getSnapshot`, and `saveSnapshot`, so the guard covers every entry path shown in the full file. New tests exercise the traversal string directly against the real `planReplaySnapshotPath`/`exportReplaySnapshot` functions (not a fabricated stand-in), confirming `calls` stays empty on rejection, which is a genuine regression test for #7796.

Nits — 5 non-blocking
  • codecov/patch reports 0.00% coverage on the diff despite the new tests directly exercising the changed lines in `replay-snapshot.ts:79-85`; this is likely a coverage-reporting/base-branch artifact (branch is 1 commit behind default) rather than a real gap, but worth confirming the patch report picks up `replay-snapshot.ts` correctly since the tests clearly hit those lines.
  • 'Contributor trust — flagged for review' is a repo-process signal, not a code defect, but should be resolved through your normal contributor-vetting flow.
  • The JSDoc comment on `COMMIT_SHA_PATTERN` (replay-snapshot.ts:78) is a reasonable non-obvious explanation of the shared convention with `replay-task-generation.ts` and is fine as-is.
  • Since `normalizeCommitSha`'s regex duplicates `replay-task-generation.ts`'s pattern verbatim, consider extracting a shared `COMMIT_SHA_PATTERN`/`normalizeCommitSha` helper into a common module to avoid future drift between the two guards.
  • Double check the codecov/patch failure isn't masking an untested branch elsewhere in the diff (e.g., the `.toLowerCase()` path is tested via the case-normalization test, but confirm the coverage tool is scoped to the right file).

CI checks failing

  • codecov/patch — 0.00% of diff hit (target 99.00%)
Flagged checks (non-blocking)
  • Contributor trust — Contributor flagged for review

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

Addressed
normalizeCommitSha now enforces the same /^[0-9a-f]{7,40}$/i hex-shaped check used in replay-task-generation.ts before path.join, and the diff adds a regression test that a path-traversal-shaped commitSha (containing ../) is rejected with invalid_commit_sha, plus tests for non-hex/too-short rejection and case normalization.

Review context
  • Author: bohdansolovie
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, C++, JavaScript
  • Official Gittensor activity: 64 PR(s), 7 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 (CI is failing (codecov/patch)). 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.

@loopover-orb loopover-orb Bot closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. 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