Skip to content

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

Closed
andriypolanski wants to merge 3 commits into
JSONbored:mainfrom
andriypolanski:fix/7796-replay-snapshot-sha-guard-v2
Closed

fix(miner): reject non-hex commitSha in replay-snapshot path planner (#7796)#7995
andriypolanski wants to merge 3 commits into
JSONbored:mainfrom
andriypolanski:fix/7796-replay-snapshot-sha-guard-v2

Conversation

@andriypolanski

Copy link
Copy Markdown
Contributor

Summary

Closes #7796

Change

  • Guard (packages/loopover-miner/lib/replay-snapshot.ts): after trim, require COMMIT_SHA_PATTERN (/^[0-9a-f]{7,40}$/i). Shared by planReplaySnapshotPath, exportReplaySnapshot, and store getSnapshot/saveSnapshot.
  • Tests (test/unit/miner-replay-snapshot.test.ts):
    • Import the .ts source (not .js) so coverage attributes to the file Codecov patch grades — CI runs build:miner before coverage, which writes a sibling gitignored .js; a .js import then resolves to that compiled file and can report 0% patch on the .ts diff (root cause of closed fix(miner): validate commit SHA is a safe path segment in replay-snapshot planner (#7796) #7992).
    • Fixtures updated to hex-valid 7+ char SHAs (abc123abc1234, etc.).
    • Regression coverage: path-traversal / non-hex / too-short / whitespace rejection; trimmed full SHA confined under REPLAY_SNAPSHOT_SUBDIR; exportReplaySnapshot rejects before any git work; store getSnapshot/saveSnapshot reject.

Validation

  • git diff --check clean.
  • npx vitest run test/unit/miner-replay-snapshot.test.ts — all green (after npm run build:miner, matching CI).
  • Codecov patch = 100%. Verified from coverage/lcov.info with compiled .js present: every added executable line hit (COMMIT_SHA_PATTERN, trimmed, regex if, return); regex branch arms both [hit].

UI Evidence

N/A — miner lib hardening only; no UI surface changed.

Made with Cursor

…SONbored#7796)

normalizeCommitSha only trimmed and non-empty-checked its input, so a crafted
value such as "../../etc" flowed into planReplaySnapshotPath's path.join and
escaped REPLAY_SNAPSHOT_SUBDIR. Apply the same /^[0-9a-f]{7,40}$/i guard
replay-task-generation.ts already uses, and import the .ts source in the unit
test so Codecov patch grades the real diff under CI's build:miner-before-
coverage layout (the failure mode that closed JSONbored#7992 at 0%).

Co-authored-by: Cursor <cursoragent@cursor.com>
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

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

loopover-orb Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This repository reviews pull requests one-shot: the PR must be correct as originally opened. Pushing an additional commit closes it automatically instead of restarting review — open a fresh pull request with every fix included.

@loopover-orb loopover-orb Bot added the review-evasion Gittensor contributor context label Jul 22, 2026
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. review-evasion Gittensor contributor context

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

2 participants