Skip to content

fix(content-lane): reject a non-integer subnet netuid instead of coercing it to subnet 0 - #9782

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/subnet-netuid-integer-9665
Jul 29, 2026
Merged

fix(content-lane): reject a non-integer subnet netuid instead of coercing it to subnet 0#9782
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/subnet-netuid-integer-9665

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What & why

assessSubnetDocument (src/review/content-lane/registry-logic.ts) is the content lane's shape validator for a registry subnet file. Its root-netuid check was:

if (!Number.isInteger(Number(doc.netuid))) {  }

Number() coerces before the integer test, so values the message promises it rejects slipped through: Number(null) === 0, Number("") === 0, Number([]) === 0, Number(true) === 1, Number("0x10") === 16, Number(" 7 ") === 7. A document with "netuid": null was therefore accepted as subnet 0 and threaded into assessSurfaceEntry's consistency check as if it had been validated — its comment even relies on "the document validator already proved the root netuid is an integer". A surface declaring netuid: 0 then matched the fabricated root and could reach a decisive merge on the surface lane.

The fix

Validate the raw value type-first, mirroring the !Array.isArray(doc.surfaces) sibling three lines below (which never coerces):

if (typeof doc.netuid !== "number" || !Number.isInteger(doc.netuid) || doc.netuid < 0) {
  return fail("unsupported-shape", "Subnet document netuid must be an integer.");
}
const netuid = doc.netuid; // already validated; no coercion on this path

A netuid is a non-negative index, so a negative integer is rejected too; 0 stays valid. The failure summary and unsupported-shape reason code are unchanged (they're asserted by existing tests and rendered into the public close comment). No change to assessSurfaceEntry or any other branch.

Tests (test/unit/content-lane-registry-logic.test.ts)

  • Table-driven #9665 case: each of null, "", true, [], [5], "7", "0x10", 1.5, -1, undefinedunsupported-shape with the exact summary text. 9 of these fail against main.
  • netuid: 0 and netuid: 64 still produce a non-unsupported-shape outcome (not over-tightened).
  • End-to-end regression (Deliverable 3): a document with netuid: null and a surface declaring netuid: 0 no longer reaches merged — it fails on unsupported-shape.
  • Updated the existing "string root coerces → merged" case, which encoded the removed behaviour, to assert an integer root threads through and a conflicting entry netuid is rejected.

Validation

  • npm run typecheck green; the suite (171 tests) green.
  • Diff coverage on the changed file is 100% line and branch (all three arms of the new guard); whole-file branch 100%.
  • git diff --check <base> HEAD clean; diff is two files, no route/schema/migration change.

Closes #9665

…cing it to subnet 0

`assessSubnetDocument`'s root-netuid check was `!Number.isInteger(Number(doc.netuid))`.
Number() coerces before the integer test, so values the message promises it
rejects slipped through: Number(null)===0, Number("")===0, Number([])===0,
Number(true)===1, Number("0x10")===16, Number("  7  ")===7. A document with
`netuid: null` was accepted as subnet 0 and threaded into assessSurfaceEntry's
consistency check as if validated — a surface declaring `netuid: 0` then matched
it and could reach a decisive merge on the surface lane.

Validate the raw value type-first, mirroring the `!Array.isArray(doc.surfaces)`
sibling three lines below: reject unless `doc.netuid` is already a `number` that
`Number.isInteger` accepts and is non-negative (a netuid is a non-negative index;
0 stays valid). The summary text and `unsupported-shape` reason are unchanged, and
`const netuid` now reads the validated number directly with no coercion.

Closes JSONbored#9665
@shin-core
shin-core requested a review from JSONbored as a code owner July 29, 2026 08:27
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 29, 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.

@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-29 08:37:14 UTC

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

⏸️ Suggested Action - Manual Review

Review summary
This PR replaces the coercive `!Number.isInteger(Number(doc.netuid))` root netuid check in `assessSubnetDocument` (registry-logic.ts:555) with a type-first check that validates the raw value, matching the pattern used by the `!Array.isArray(doc.surfaces)` sibling three lines below. The fix correctly closes the described hole: `Number(null)`, `Number("")`, `Number([])`, `Number(true)`, hex strings, and negative integers are now rejected rather than silently coerced to a valid subnet id. Downstream, `assessSurfaceEntry`'s comment claiming 'the document validator already proved the root netuid is an integer' is now actually true post-fix, closing the surface-lane merge risk described in the PR body. Tests are table-driven and directly exercise the reject/accept boundary including the exact null/0-collision exploit scenario.

Nits — 3 non-blocking
  • The PR body claims 9 of the 10 table-driven bad-netuid cases fail against main, but this can't be independently verified from the diff alone — worth confirming in CI output if scrutinized further.
  • assessSubnetDocument's per-field secret scan happens before the netuid check in the visible code path, so ordering of validation vs the new netuid guard is unchanged, but it's worth double-checking no other caller relies on the old coercive Number(doc.netuid) behavior for netuid values like whitespace-padded numeric strings (e.g. " 7 ") that some external tooling might still emit.
  • Consider linking this PR explicitly to issue orb(content-lane): assessSubnetDocument accepts null/""/true as a valid netuid #9665 in the title/description if not already done via GitHub's closing-keyword convention, since the review-scope policy requires every contributor PR to close an eligible issue.

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 #9665
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 ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 50 registered-repo PR(s), 35 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 50 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: significant
Linked issue satisfaction

Addressed
The diff replaces the coercive Number(doc.netuid) check with a type-first validation matching the required Array.isArray sibling pattern, rejects negative integers, removes Number() from the netuid assignment at :558, and adds the required table-driven test plus the named null/surface-0 regression test.

Review context
  • Author: shin-core
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is registered but has no active allocation in the current snapshot.
  • Public profile languages: not available
  • Official Gittensor activity: 50 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Await review-lane availability.
  • Then work through the remaining 2 steps in the Signals table above.
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

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.69%. Comparing base (47842ec) to head (203f882).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9782      +/-   ##
==========================================
+ Coverage   76.58%   76.69%   +0.10%     
==========================================
  Files         282      283       +1     
  Lines       59464    59740     +276     
  Branches     6555     6673     +118     
==========================================
+ Hits        45543    45819     +276     
  Misses      13639    13639              
  Partials      282      282              
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/review/content-lane/registry-logic.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 29, 2026
@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Held for manual review: the gate and required CI are green, but GitHub reports this pull request's mergeable state as unstable because a non-required check or status is not passing, so LoopOver will not auto-merge. A maintainer can resolve the failing check or review and merge manually. This is an automated maintenance action.

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 29, 2026
@JSONbored
JSONbored merged commit 1202e89 into JSONbored:main Jul 29, 2026
9 of 10 checks passed
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. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

orb(content-lane): assessSubnetDocument accepts null/""/true as a valid netuid

2 participants