Skip to content

fix(bounties): type-guard normalizeGittBountySnapshot's untrusted Gitt payload fields - #9335

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-bounty-snapshot-typeguards
Jul 27, 2026
Merged

fix(bounties): type-guard normalizeGittBountySnapshot's untrusted Gitt payload fields#9335
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-bounty-snapshot-typeguards

Conversation

@kai392

@kai392 kai392 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

normalizeGittBountySnapshot (src/bounties/ingest.ts) parses a payload: unknown from the
untrusted Gitt API, cast to GittIssueListPayload — so the declared field types are not
guaranteed at runtime. The old guard only truthiness-checked the fields, so a wrong-typed value
(e.g. a numeric repository_full_name, or a string issue_number) flowed straight into a mistyped
BountyRecord, violating the contract in src/types.ts (repoFullName: string, issueNumber: number,
status: string).

Adds typed value guards mirroring the sibling src/registry/normalize.ts convention:

  • A wrong-typed required field (id, repoFullName, issueNumber, status) drops the whole record.
  • A wrong-typed / non-finite amount degrades to undefined without dropping the record.

Test plan

  • New test/unit/bounties-ingest.test.ts: each required field wrong-typed → record dropped; well-typed records (string id via bounty_alpha; numeric id via bounty_amount) preserved; non-finite/absent amount → amountText: undefined; null/malformed payload → []
  • 100% branch coverage (24/24) on the guarded function; non-vacuity verified (reverting the guards makes the wrong-typed drop cases fail)
  • tsc --noEmit clean (engine rebuilt); 11/11 tests pass

Closes #9313

@kai392
kai392 requested a review from JSONbored as a code owner July 27, 2026 13:17
@superagent-security

Copy link
Copy Markdown
Contributor

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

…t payload fields

normalizeGittBountySnapshot parses a `payload: unknown` from the untrusted Gitt API, cast to
GittIssueListPayload — so its declared field types are not guaranteed at runtime. The old guard only
truthiness-checked the fields, letting a wrong-typed value (e.g. a numeric repository_full_name or a
string issue_number) flow straight into a mistyped BountyRecord. Add typed value guards mirroring
registry/normalize.ts's convention: a wrong-typed required field (id, repoFullName, issueNumber,
status) drops the whole record, and a wrong-typed/non-finite amount degrades to undefined without
dropping the record.

Closes JSONbored#9313

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.38%. Comparing base (f7dda79) to head (762abad).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9335   +/-   ##
=======================================
  Coverage   75.38%   75.38%           
=======================================
  Files         275      276    +1     
  Lines       58023    58036   +13     
  Branches     6181     6186    +5     
=======================================
+ Hits        43739    43752   +13     
  Misses      14014    14014           
  Partials      270      270           
Flag Coverage Δ
backend 100.00% <100.00%> (?)

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

Files with missing lines Coverage Δ
src/bounties/ingest.ts 100.00% <100.00%> (ø)

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

loopover-orb Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-27 13:27:12 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR replaces truthiness-only checks in normalizeGittBountySnapshot with real runtime type guards (typeof + Number.isFinite) for id, repository_full_name, issue_number, and status, matching BountyRecord's declared contract and the sibling registry/normalize.ts convention. The logic is correct: a wrong-typed required field now drops the record entirely, and amountText degrades to undefined on a non-finite/absent bounty_amount rather than propagating NaN or a garbage string. Tests cover each required-field failure mode individually plus both amountText branches (bounty_alpha string vs numeric bounty_amount vs neither), giving solid branch coverage of the new guard; the change is narrowly scoped to the stated issue #9313.

Nits — 3 non-blocking
  • The inline comment block above the guard (src/bounties/ingest.ts) is fairly long for what the code itself already makes clear via typeof checks; could be trimmed.
  • No test exercises a `bounty_amount` that's a wrong-typed non-number (e.g. string) alongside a present `bounty_alpha`, though this is implicitly covered by the ternary structure.
  • Consider extracting the repeated `typeof x === 'string' && x.length > 0`-style pattern into a small stringValue/numberValue helper as registry/normalize.ts does, for consistency across normalizers (src/bounties/ingest.ts vs src/registry/normalize.ts).

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

Partially addressed
The diff correctly implements type guards for id, repoFullName, issueNumber, status, and amountText degradation exactly as required, but the required tests were added to a new file test/unit/bounties-ingest.test.ts instead of the existing test/unit/adapters.test.ts explicitly named in the issue's Deliverables and Test Coverage Requirements.

Review context
  • Author: kai392
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, Cuda, JavaScript, Kotlin, Perl, TypeScript, Vue
  • Official Gittensor activity: 96 PR(s), 6 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 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 1227894 into JSONbored:main Jul 27, 2026
8 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(bounties): normalizeGittBountySnapshot trusts untyped fields from the untrusted Gitt payload

2 participants