Skip to content

fix(db): escape review-burst repo prefix matching - #3973

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-unescaped-like-query-vulnerability
Jul 7, 2026
Merged

fix(db): escape review-burst repo prefix matching#3973
JSONbored merged 1 commit into
mainfrom
codex/fix-unescaped-like-query-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The review-burst query used an unescaped LIKE pattern built from repoFullName, so _/% in repo names could act as wildcards and cause cross-repo matching and misattributed ops alerts.
  • This polluted ops telemetry (anomaly strings and Sentry logs) and could surface another repo's targetKey under the wrong repository.

Description

  • Escape SQL LIKE metacharacters before building the prefix pattern by adding escapeSqlLikePattern() and using targetPrefixPattern = ${escapeSqlLikePattern(repoFullName)}#%``.
  • Replace the Drizzle like(...) predicate with a raw SQL fragment using LIKE ... ESCAPE '\' to ensure metacharacters are literal.
  • Remove the now-unused like import from src/db/repositories.ts.
  • Add a regression unit test in test/unit/db-parsers.test.ts that proves owner/foo_bar does not match owner/fooXbar#... (covers the underscore-case regression).

Testing

  • Ran npm run typecheck and it succeeded.
  • Ran the focused unit tests with npx vitest run test/unit/db-parsers.test.ts and the file's suite passed (the new regression test included).
  • Attempted the full local coverage run (npm run test:coverage) but the repository's full test suite did not finish in this environment before the run was stopped; the added focused unit test and typecheck were used to validate the fix.

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

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

@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-07 08:24:38 UTC

2 files · 1 AI reviewer · 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.

Review summary
This PR fixes a real SQL LIKE injection-adjacent bug: repoFullName was interpolated unescaped into a LIKE pattern, so literal `_`/`%` characters in a repo name would act as wildcards and could match audit events from a different repo, corrupting the review-burst hottest-target computation. The fix correctly escapes backslash, percent, and underscore before building the prefix pattern and switches to a raw SQL fragment with `ESCAPE '\'` so the escaping actually takes effect against the Drizzle-generated query; the removed `like` import is consistent with no longer using the Drizzle helper. The added regression test directly exercises the previously-broken case (`owner/foo_bar` vs `owner/fooXbar`) and asserts the correct row/count is returned, which is a meaningful, non-fabricated test of the real code path.

Nits — 4 non-blocking
  • The escape regex `/[\\%_]/g` with replacement `"\\$&"` is correct but relies on backslash also being escaped first in the same pass via character-class ordering — worth a one-line comment or a test case with a literal backslash/percent in the repo name (not just underscore) to fully pin the escaping behavior in db-parsers.test.ts.
  • The updated `v8 ignore next` comment references 'the escaped LIKE predicate' generically; consider keeping a brief note that this still relies on SQL LIKE-against-NULL returning NULL rather than true, since that's the actual invariant being ignored for coverage.
  • Add a regression test case with `%` and `\` characters in repoFullName (not just `_`) to fully cover escapeSqlLikePattern's replacement branches per the stated coverage bar.
  • Consider extracting escapeSqlLikePattern to a shared util if other LIKE-based queries in repositories.ts build patterns from user-controlled strings, to avoid the same class of bug recurring elsewhere.

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 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: 51 registered-repo PR(s), 43 merged, 343 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 343 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), 343 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

@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.68%. Comparing base (b8a1186) to head (958ee4b).
⚠️ Report is 19 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3973   +/-   ##
=======================================
  Coverage   93.68%   93.68%           
=======================================
  Files         373      373           
  Lines       34895    34897    +2     
  Branches    12768    12768           
=======================================
+ Hits        32692    32694    +2     
  Misses       1584     1584           
  Partials      619      619           
Files with missing lines Coverage Δ
src/db/repositories.ts 96.62% <100.00%> (+<0.01%) ⬆️
🚀 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 manual-review Gittensor contributor context label Jul 7, 2026
@JSONbored
JSONbored merged commit e913a8c into main Jul 7, 2026
10 checks passed
@JSONbored
JSONbored deleted the codex/fix-unescaped-like-query-vulnerability branch July 7, 2026 08:26
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