Skip to content

fix(mcp): bound opportunity target fanout - #4072

Merged
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-resource-exhaustion-vulnerability
Jul 8, 2026
Merged

fix(mcp): bound opportunity target fanout#4072
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-resource-exhaustion-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent authenticated callers from amplifying D1/Worker/GitHub work by submitting unbounded or duplicated targets to the opportunity discovery flow.
  • Ensure the MCP tool and HTTP route reject oversized input early and that deduplication happens before any per-target authorization or repository lookup.

Description

  • Added shared limits and constants exported from src/mcp/find-opportunities.ts: MAX_FIND_OPPORTUNITIES_TARGETS, MAX_FIND_OPPORTUNITIES_OWNER_LENGTH, MAX_FIND_OPPORTUNITIES_REPO_LENGTH, MAX_FIND_OPPORTUNITIES_LANGUAGES, and MAX_FIND_OPPORTUNITIES_LANGUAGE_LENGTH and used them in validation.
  • Updated validateFindOpportunitiesInput to trim, validate, cap, and deduplicate targets and to validate language input before returning, and to return normalized targets for downstream use.
  • Applied the same caps to the MCP tool Zod schema in src/mcp/server.ts so oversized MCP requests are rejected at the tool boundary.
  • Classified /v1/opportunities/find as an expensive route in src/auth/rate-limit.ts to reduce rate-limit abuse amplification, and added regression tests covering caps, deduplication, MCP rejection, and route classification.

Testing

  • Ran unit tests with npx vitest run test/unit/find-opportunities.test.ts test/unit/mcp-find-opportunities.test.ts test/unit/auth.test.ts and all selected tests passed.
  • Ran git diff --check as a preflight sanity check and it succeeded.
  • Attempted targeted coverage collection (npm run test:coverage for the selected tests) and the selected tests ran but coverage remapping failed with TypeError: jsTokens is not a function after the tests completed.
  • Ran npx tsc --noEmit which surfaced pre-existing unrelated syntax errors in src/queue/processors.ts and is not caused by this change.

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.66%. Comparing base (95d2113) to head (4eb8e47).
⚠️ Report is 12 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4072   +/-   ##
=======================================
  Coverage   93.65%   93.66%           
=======================================
  Files         384      384           
  Lines       35865    35886   +21     
  Branches    13160    13168    +8     
=======================================
+ Hits        33589    33612   +23     
  Misses       1618     1618           
+ Partials      658      656    -2     
Files with missing lines Coverage Δ
src/auth/rate-limit.ts 98.83% <ø> (ø)
src/mcp/find-opportunities.ts 73.50% <100.00%> (+7.87%) ⬆️
src/mcp/server.ts 94.91% <ø> (ø)
🚀 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:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 7, 2026
@loopover-orb

loopover-orb Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-08 05:18:33 UTC

6 files · 2 blockers · readiness 93/100 · CI green · clean

⏸️ Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

Concerns raised — review before merging

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
Signal Result Evidence
Code review ❌ 2 blockers No AI review summary
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
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 (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 51 registered-repo PR(s), 43 merged, 505 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 505 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 51 PR(s), 505 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
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.

🟩 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 added the manual-review Gittensor contributor context label Jul 7, 2026
@JSONbored
JSONbored force-pushed the codex/propose-fix-for-resource-exhaustion-vulnerability branch 2 times, most recently from 83e43ad to b8baee3 Compare July 8, 2026 03:40
@JSONbored
JSONbored force-pushed the codex/propose-fix-for-resource-exhaustion-vulnerability branch from b8baee3 to 4eb8e47 Compare July 8, 2026 04:03
@JSONbored
JSONbored merged commit 5bfa6cb into main Jul 8, 2026
10 checks passed
@JSONbored
JSONbored deleted the codex/propose-fix-for-resource-exhaustion-vulnerability branch July 8, 2026 05:22
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. manual-review Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

1 participant