Skip to content

fix(stats): scope reuse trend to public repos - #4991

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-public-stats-endpoint-vulnerability
Jul 11, 2026
Merged

fix(stats): scope reuse trend to public repos#4991
JSONbored merged 1 commit into
mainfrom
codex/fix-public-stats-endpoint-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent unauthenticated information disclosure from the public /v1/public/stats payload by stopping global aggregation of audit github_app.*_cache_* and ai_review reuse events that could include private/non-allowlisted repos.
  • Preserve the public trend behavior and the low-sample suppression semantics while ensuring only explicitly opted-in repositories contribute to the unauthenticated payload.

Description

  • Import and use publicStatsProjects from src/review/public-stats.ts and thread the parsed allowlist into the reuse-rate loader.
  • Filter the audit_events query by the parsed target_key repo (handles both owner/repo and owner/repo#number shapes) and skip querying when the allowlist is empty.
  • Adjust loadReuseRateDayRows signature to accept projects: string[] and return an empty array when the allowlist is empty, preserving the fail-safe behavior.
  • Add regression unit tests in test/unit/public-reuse-rate-trend.test.ts to verify: allowlisted events are counted, non-allowlisted events are excluded, and the empty-allowlist case returns all-zero buckets.

Testing

  • Ran type checking with npm run typecheck, which succeeded.
  • Ran targeted unit tests with npx vitest run test/unit/public-reuse-rate-trend.test.ts, which passed.
  • Built the miner (npm run build:miner) and ran the public-stats integration route tests npx vitest run test/integration/public-stats-route.test.ts, which passed.
  • Attempted the full coverage suite with npm run test:coverage, but the full run did not complete in this environment due to long-running/unrelated queue/watchdog tests; the specific regression/unit and integration tests validating this change passed as noted above.

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 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.31%. Comparing base (7bbf529) to head (bbe1af7).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4991   +/-   ##
=======================================
  Coverage   94.31%   94.31%           
=======================================
  Files         454      454           
  Lines       39034    39037    +3     
  Branches    14234    14235    +1     
=======================================
+ Hits        36813    36816    +3     
  Misses       1572     1572           
  Partials      649      649           
Flag Coverage Δ
shard-1 46.62% <0.00%> (-0.29%) ⬇️
shard-2 33.66% <75.00%> (+0.42%) ⬆️
shard-3 31.41% <0.00%> (+0.04%) ⬆️
shard-4 32.57% <100.00%> (-0.49%) ⬇️
shard-5 34.46% <50.00%> (+0.92%) ⬆️
shard-6 45.47% <0.00%> (+0.23%) ⬆️

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

Files with missing lines Coverage Δ
src/services/public-reuse-rate-trend.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

loopover-orb Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Caution

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

🛑 Gittensory review result - fixes required

Review updated: 2026-07-11 13:49:04 UTC

2 files · 1 AI reviewer · 2 blockers · readiness 93/100 · CI failing · unstable

🛑 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.

Review summary
This narrows the reuse-rate trend query to only count audit_events whose target_key repo is in the public-stats allowlist, replacing a previously deliberate global aggregation with a scoped one — mirroring the exact LOWER(target_key-prefix) IN (projects) pattern already used in public-review-volume-trend.ts's loadOwnLedgerDayRows. The parameter binding order (reuseType placeholders x2, then projects, then sinceIso) matches the query's placeholder order, the empty-allowlist short-circuit preserves fail-safe behavior, and the new tests exercise both the '#'-suffixed and bare target_key shapes plus allowlist exclusion. No linked eligible open issue is visible in the PR description for this fix — per repo policy, that needs to be added or the maintainer-authorization confirmed before this is merge-ready, independent of the code correctness below.

Nits — 4 non-blocking
  • codecov/patch failed at 50% coverage on this diff — confirm the branch where target_key is NULL or has no '#' is actually exercised by a test, since patch coverage this low on a small diff suggests a real gap, not just noise from unrelated files.
  • src/services/public-reuse-rate-trend.ts:93 relies on `projects` already being lowercased by publicStatsProjects() since the SQL only LOWER()s the target_key side, not the projects list — this mirrors the existing convention in public-review-volume-trend.ts so it's likely fine, but worth a one-line comment noting the assumption since a future caller passing mixed-case projects would silently under-match.
  • Add a comment near `projectPlaceholders` cross-referencing public-review-volume-trend.ts's loadOwnLedgerDayRows so the two nearly-identical allowlist-scoping queries are easy to keep in sync if the target_key convention ever changes.
  • Confirm/paste the linked issue number in the PR description per repo convention for external contributor PRs.

Why this is blocked

  • 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.

CI checks failing

  • validate-tests-merge
  • validate
  • codecov/patch — 50.00% of diff hit (target 99.00%)
  • validate-tests (4)
Signal Result Evidence
Code review ❌ 2 blockers 1 reviewer
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: 46 registered-repo PR(s), 38 merged, 416 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 46 PR(s), 416 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence.
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: not available
  • Official Gittensor activity: 46 PR(s), 416 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 11, 2026
@JSONbored
JSONbored merged commit f22516c into main Jul 11, 2026
27 of 31 checks passed
@JSONbored
JSONbored deleted the codex/fix-public-stats-endpoint-vulnerability branch July 11, 2026 13:50
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant