Skip to content

fix(scenarios): reject non-array changedFiles that bypasses the source-upload scan - #8467

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-8328-scenario-changedfiles-nonarray
Jul 24, 2026
Merged

fix(scenarios): reject non-array changedFiles that bypasses the source-upload scan#8467
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-8328-scenario-changedfiles-nonarray

Conversation

@jeffrey701

Copy link
Copy Markdown
Contributor

What

assertScenarioLocalBranchInputSafe is a safety-boundary validator — it exists to refuse
source content ("source contents are never uploaded") and oversized payloads
("metadata-only paths are required") in scenario local-branch inputs. But its changedFiles
handling was gated on Array.isArray(changedFiles): a present-but-non-array value (a
plain object like { diff: "…5000 chars of source…" }, or a bare string) fell through the
Array.isArray guard entirely, so the nested forbidden-key/oversize scan never ran and the
function returned normally — silently accepting exactly the kind of payload it exists to
reject. The outer top-level-key loop only inspects payload's own keys; it does not recurse
into a non-array changedFiles value, so nothing else caught it either.

Change

Reject a present, non-array changedFiles outright, before the Array.isArray block:

if (changedFiles !== undefined && !Array.isArray(changedFiles)) {
  throw new Error("Refusing non-array changedFiles; an array of file entries is required.");
}

Behavior for every already-correct case is unchanged: a valid array of entries (with or
without forbidden keys / oversized values) still runs the full scan, and an omitted /
undefined changedFiles is still allowed.

Validation

  • New regression test in test/unit/scenario-input-model.test.ts: both
    assertScenarioLocalBranchInputSafe({ changedFiles: { diff: "x".repeat(5000) } }) and
    assertScenarioLocalBranchInputSafe({ changedFiles: "not-an-array" }) now throw, while a
    valid array and an omitted changedFiles still do not.
  • npx vitest run test/unit/scenario-input-model.test.ts → all pass; 100% branch coverage on
    the new guard (both operands, both sides, verified via lcov).
  • Full npm run test:changed net green (modulo the pre-existing Windows-only
    subprocess/symlink baseline failures that pass on Linux CI).

Closes #8328

@jeffrey701
jeffrey701 requested a review from JSONbored as a code owner July 24, 2026 14:18
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (6c25eb6) to head (4e4c5d1).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8467      +/-   ##
==========================================
- Coverage   92.45%   89.62%   -2.84%     
==========================================
  Files         791       98     -693     
  Lines       79320    22790   -56530     
  Branches    23954     3898   -20056     
==========================================
- Hits        73335    20425   -52910     
+ Misses       4858     2187    -2671     
+ Partials     1127      178     -949     
Flag Coverage Δ
shard-1 57.14% <0.00%> (-1.23%) ⬇️
shard-2 65.47% <0.00%> (+14.36%) ⬆️
shard-3 100.00% <100.00%> (+46.57%) ⬆️

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

Files with missing lines Coverage Δ
src/scenarios/input-model.ts 100.00% <100.00%> (ø)

... and 693 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 24, 2026
@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-24 14:51:38 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This is a narrow, correctly-targeted security fix: `assertScenarioLocalBranchInputSafe` previously only scanned `changedFiles` when it was an array, so a plain object or string value bypassed the forbidden-key/oversize scan entirely and could smuggle source content past this safety boundary. The fix adds an explicit `Array.isArray` negative-case guard before the existing positive-case block, throwing on any present non-array value while leaving the array and undefined paths untouched. The regression test directly exercises both the object and string bypass shapes plus confirms the valid-array and omitted cases still pass, which is exactly the coverage this change needs.

Nits — 3 non-blocking
  • src/scenarios/input-model.ts:199-204 — the new guard duplicates the `Array.isArray(changedFiles)` check as two separate `if` blocks; an `else` or a single branch (array vs non-undefined-non-array) would read more clearly, though this is purely stylistic.
  • The inline comments in both the source and test files are fairly verbose for what the code already makes clear from the error message and test name.
  • Consider consolidating the two adjacent `Array.isArray` checks in src/scenarios/input-model.ts into a single conditional (e.g. `if (changedFiles !== undefined) { if (!Array.isArray(changedFiles)) throw …; else { … } }`) for readability.

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

Addressed
The diff adds the exact guard the issue requests (throw on present, non-array changedFiles) and includes regression tests for the object and string bypass cases plus confirmation that valid array and omitted changedFiles still pass.

Review context
  • Author: jeffrey701
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 66 PR(s), 17 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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 04d38b6 into JSONbored:main Jul 24, 2026
12 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.

assertScenarioLocalBranchInputSafe silently skips its forbidden-key/oversize checks when changedFiles is not an array

1 participant