Skip to content

feat(miner-extension): reject oversized pasted ranked-candidates JSON before saving - #5525

Closed
joaovictor712 wants to merge 1 commit into
JSONbored:mainfrom
joaovictor712:feat/miner-extension-json-paste-size-limit
Closed

feat(miner-extension): reject oversized pasted ranked-candidates JSON before saving#5525
joaovictor712 wants to merge 1 commit into
JSONbored:mainfrom
joaovictor712:feat/miner-extension-json-paste-size-limit

Conversation

@joaovictor712

Copy link
Copy Markdown
Contributor

Summary

  • The miner extension accepted an arbitrarily large pasted JSON blob into the options page's ranked-candidates
    textarea with no size bound at all. The extension does not request the unlimitedStorage permission, so
    chrome.storage.local is capped at its default ~10 MiB QUOTA_BYTES quota shared across every key — an
    oversized paste could silently fail to save (Chrome rejects the set() call) or leave storage in a partial
    state, with no clear feedback to the contributor about why.
  • options.js's parseRankedCandidatesJson now checks the raw pasted text's length against a new
    MAX_RANKED_CANDIDATES_JSON_CHARS bound (8 MiB of UTF-16 characters) before attempting JSON.parse — so
    an oversized-but-invalid paste fails with a clear "too large" error rather than a confusing JSON syntax error,
    and a valid-but-oversized paste never reaches chrome.storage.local.set at all.
  • The bound is checked against text.length (UTF-16 code units), not a TextEncoder-based byte count: this
    content script ships unbundled (no build step), and TextEncoder also isn't available in this repo's
    node:vm-based unit-test harness for these scripts, so a plain length check keeps the logic portable and
    directly testable. 8 MiB of characters stays comfortably under the 10 MiB quota even accounting for multi-byte
    UTF-8 expansion once actually persisted.

Fixes #4863

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally — this change lives entirely under apps/gittensory-miner-extension/** and its dedicated test file test/unit/miner-extension-content.test.ts, outside vitest's root coverage.include glob (only root src/** is Codecov-measured), so codecov/patch cannot see this diff.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

Ran the full local gate: npm run test:ci (798 test files, 0 failures) and npm audit --audit-level=moderate (0 vulnerabilities), both clean on the final rebased commit.

Test coverage added to test/unit/miner-extension-content.test.ts (now 21 tests total, up from 18): rejecting a payload one character over the bound with a clear "too large" error, and specifically asserting the size check fires before JSON.parse runs (proven with a non-JSON oversized string, checking the thrown error is not a JSON syntax error); accepting a payload of exactly the boundary length (MAX_RANKED_CANDIDATES_JSON_CHARS chars, not one over); and a regression test driving the real form-submit save flow end-to-end with an oversized paste, asserting the error surfaces through showStatus and chrome.storage.local.set is never called (zero partial writes).

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. — N/A, no auth/session/CORS surface touched (local chrome.storage only).
  • API/OpenAPI/MCP behavior is updated and tested where needed. — no public API/OpenAPI/MCP surface touched; this only guards a local chrome.storage.local write path.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. — the error path is driven through the real parseRankedCandidatesJson/showStatus code, not a mock of the validation itself.
  • Visible UI changes include a UI Evidence section below.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. — updated apps/gittensory-miner-extension/README.md's "Local ranked cache" section.

UI Evidence

This is a browser extension options page — there is no hosted/public deployment to screenshot from this
environment (no browser screenshot tooling available here). Verified functionally instead: npm run test:ci
includes the full test/unit/miner-extension-content.test.ts suite (21/21 passing), including a regression test
that drives the real options-page save flow with an oversized paste and asserts the visible status message
matches /too large/i while chrome.storage.local.set is never invoked.

Notes

  • Chose a plain UTF-16 text.length check over TextEncoder-based byte counting to keep this portable across
    the unbundled content-script runtime and the repo's node:vm test harness for these files, at the cost of
    being an approximation rather than an exact byte count — the 8 MiB bound leaves comfortable headroom under the
    10 MiB chrome.storage.local quota to absorb that approximation.
  • Did not request the unlimitedStorage permission as an alternative fix; the issue's proposal was a bounded,
    validated paste path with a clear error, not expanding the extension's storage footprint.

… before saving

The extension doesn't request the unlimitedStorage permission, so
chrome.storage.local is capped at its default ~10 MiB quota with no
guard against an unbounded paste silently failing to save. Reject a
paste over a conservative size bound with a clear error, before ever
attempting to parse or save it.

Fixes #4863
@joaovictor712
joaovictor712 requested a review from JSONbored as a code owner July 13, 2026 01:13
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.79%. Comparing base (05d1fb0) to head (510d361).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5525   +/-   ##
=======================================
  Coverage   94.79%   94.79%           
=======================================
  Files         566      566           
  Lines       45065    45065           
  Branches    14675    14675           
=======================================
  Hits        42718    42718           
  Misses       1613     1613           
  Partials      734      734           
Flag Coverage Δ
shard-1 43.65% <ø> (-0.56%) ⬇️
shard-2 35.53% <ø> (+0.06%) ⬆️
shard-3 32.11% <ø> (+0.16%) ⬆️
shard-4 31.35% <ø> (-0.58%) ⬇️
shard-5 33.32% <ø> (+0.45%) ⬆️
shard-6 43.72% <ø> (+0.20%) ⬆️

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 13, 2026
@loopover-orb

loopover-orb Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review result - reject/close recommended

Review updated: 2026-07-13 01:22:34 UTC

3 files · 2 AI reviewers · 1 blocker · readiness 100/100 · CI green · clean

🛑 Suggested Action - Reject/Close

Review summary
This PR adds a straightforward pre-parse size guard (`trimmed.length > MAX_RANKED_CANDIDATES_JSON_CHARS`, 8 MiB of UTF-16 chars) in `parseRankedCandidatesJson` in options.js:12-16, throwing a clear error before `JSON.parse` and before `chrome.storage.local.set` is ever reached. The change is correctly scoped, closes #4863, and is well-tested: an over-limit non-JSON payload, an at-limit valid payload, and a full submit-flow regression test confirming `chrome.storage.local.set` is never called on an oversized paste. The UTF-16-length-vs-byte-size tradeoff is explicitly documented and justified (no build step, no TextEncoder in the node:vm test harness), which is a reasonable engineering call for this unbundled content script.

Blockers

  • apps/gittensory-miner-extension/options.js:17 accepts any JSON whose trimmed UTF-16 length is <= 8 MiB, so a valid array containing multibyte characters can pass `parseRankedCandidatesJson()` and still exceed `chrome.storage.local` quota at `chrome.storage.local.set`, recreating the silent/partial save failure this PR is meant to close; change the guard to measure the serialized byte size with a portable fallback or lower the bound to account for worst-case UTF-8 expansion and add a real-path test for non-ASCII input.
Nits — 5 non-blocking
  • The 8 MiB UTF-16-character bound is a proxy for byte size, not an exact one — once JSON-stringified with escaping/serialization overhead plus the `rankedCandidatesSavedAt` key, a payload right at the 8 MiB boundary could still occasionally exceed the 10 MiB quota depending on multi-byte content; worth a comment confirming this was considered acceptable headroom (already partially done in the code comment).
  • Consider surfacing the character count of a rejected paste truncated in the UI (already done via toLocaleString in the error message) so contributors know how far over they are — this is already handled well.
  • No other changes needed; the diff is narrow and directly maps to the linked issue.
  • test/unit/miner-extension-content.test.ts:158 calls `parseRankedCandidatesJson(oversized)` twice in the same test; nit: capture the thrown error once so the invariant is clearer and the test does not duplicate the expensive oversized parse path.
  • apps/gittensory-miner-extension/options.js:17 either use a small local UTF-8 byte counter instead of raw `trimmed.length`, or set the character bound low enough that worst-case persisted JSON remains below Chrome's quota.

Why this is blocked

  • apps/gittensory-miner-extension/options.js:17 accepts any JSON whose trimmed UTF-16 length is <= 8 MiB, so a valid array containing multibyte characters can pass `parseRankedCandidatesJson()` and still exceed `chrome.storage.local` quota at `chrome.storage.local.set`, recreating the silent/partial save failure this PR is meant to close; change the guard to measure the serialized byte size with a portable fallback or lower the bound to account for worst-case UTF-8 expansion and add a real-path test for non-ASCII input.
📋 Copy for AI agents — paste into your coding agent
Fix the following blocker(s) from this PR review:

1. apps/gittensory-miner-extension/options.js:17 accepts any JSON whose trimmed UTF-16 length is &lt;= 8 MiB, so a valid array containing multibyte characters can pass \`parseRankedCandidatesJson\(\)\` and still exceed \`chrome.storage.local\` quota at \`chrome.storage.local.set\`, recreating the silent/partial save failure this PR is meant to close; change the guard to measure the serialized byte size with a portable fallback or lower the bound to account for worst-case UTF-8 expansion and add a real-path test for non-ASCII input.
Signal Result Evidence
Code review ❌ 1 blocker 2 reviewers, synthesized
Linked issue ✅ Linked #4863
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: 1874 registered-repo PR(s), 1235 merged, 49 issue(s).
Contributor context ✅ Confirmed Gittensor contributor galuis116; Gittensor profile; 1874 PR(s), 49 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence. LLM value judgment: minor — This is a small, well-targeted defensive fix closing a real storage-quota footgun for a niche extension feature, not a major functional improvement.
Linked issue satisfaction

Addressed
The PR adds a size check on the pasted ranked-candidates JSON before parsing/saving, throwing a clear 'too large' error and preventing storage.set from being called on oversized input, directly matching the issue's ask for bounded paste validation with a clear error message.

Review context
  • Author: galuis116
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, Python, Dart, TypeScript, HTML, MDX, Rust, C++
  • Official Gittensor activity: 1874 PR(s), 49 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.
[BETA] Chat with Gittensory

Ask Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @gittensory ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @gittensory mention with a real question is routed to the closest matching read-only command automatically -- no exact syntax required.

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

Visual preview
Route Viewport Before (production) After (this PR's preview) Diff
/ desktop before / after /
/ mobile before / (mobile) after / (mobile)

Click any thumbnail to open the full-size screenshot. Before = production · After = this PR's preview deploy.

🟩 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 Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb

loopover-orb Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Gittensory is closing this pull request on the maintainer's behalf (AI reviewers agree on a likely critical defect: apps/gittensory-miner-extension/options.js:17 accepts any JSON whose trimmed UTF-16 length is <= 8 MiB, so a valid array containing multibyte characters can pass `parseRankedCandidatesJson()` and still exceed `chrome.storage.local` quota at `chrome.storage.local.set`, recreating the silent/partial save failure this PR is meant to close; change the guard to measure the serialized byte size with a portable fallback or lower the bound to account for worst-case UTF-8 expansion and add a real-path test for non-ASCII input.). 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add storage-size validation for pasted JSON

1 participant