Skip to content

fix(grafana): escape AI usage SQL variables#5354

Merged
JSONbored merged 2 commits into
mainfrom
codex/fix-grafana-sql-injection-vulnerability
Jul 12, 2026
Merged

fix(grafana): escape AI usage SQL variables#5354
JSONbored merged 2 commits into
mainfrom
codex/fix-grafana-sql-injection-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Close a SQL-injection confidentiality hole in the consolidated AI usage Grafana dashboard by preventing raw template-variable interpolation into SQLite queries.
  • Ensure the dashboard continues to be filterable by provider/feature/model while using Grafana's SQL-safe formatting to avoid URL-controlled query injection.

Description

  • Replaced raw '$provider', '$feature', and '$model' interpolations with Grafana ${provider:sqlstring}, ${feature:sqlstring}, and ${model:sqlstring} formatting across grafana/dashboards/ai-usage.json (template variable model query and all ai_usage_events targets).
  • Updated the unit test test/unit/selfhost-grafana-ai-usage-dashboard.test.ts to simulate Grafana SQL-string escaping by adding sqlString() and substituteSqlString() helpers and to assert the dashboard now uses ${...:sqlstring} rather than raw '$...' tokens.
  • Added a regression-style test that injects a quote-bearing URL-controlled payload and verifies it remains inside a quoted SQL string rather than enabling clause/UNION tricks.
  • Kept observability validation in place by running the repository's dashboard/schema checks to ensure the modified dashboard JSON remains syntactically valid for self-host deployment.

Testing

  • Ran npx vitest run test/unit/selfhost-grafana-ai-usage-dashboard.test.ts and all tests in that file passed (10 tests passing).
  • Ran npm run selfhost:validate-observability and the observability config validation completed successfully (dashboards and alert rules are valid).
  • Ran git diff --check as part of preflight and it reported no whitespace/conflict issues.
  • Attempted npm run test:ci but it did not complete cleanly due to a pre-existing cf-typegen:check drift message and an actionlint setup retry caused by a transient DNS/network issue, so the full test:ci gate was not green in this environment.
  • Attempted npm audit --audit-level=moderate but the npm registry audit endpoint returned 403 Forbidden, so the dependency-review step could not be completed here.

Codex Task

@JSONbored JSONbored self-assigned this Jul 12, 2026
@JSONbored JSONbored marked this pull request as draft July 12, 2026 14:49
@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 12, 2026
@loopover-orb

loopover-orb Bot commented Jul 12, 2026

Copy link
Copy Markdown

Warning

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

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-12 21:39:15 UTC

2 files · 2 blockers · readiness 89/100 · CI pending · blocked

⏸️ Suggested Action - Manual Review

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.
📋 Copy for AI agents — paste into your coding agent
Fix the following blocker(s) from this PR review:

1. No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.

2. 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 (draft PR; no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 44 registered-repo PR(s), 36 merged, 435 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 44 PR(s), 435 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Improvement ⚠️ ℹ️ Insufficient signal risk: clean · value: insufficient-signal — Nothing measurable for the structural-improvement analyzers on this PR (e.g. no code files changed).
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: 44 PR(s), 435 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.
  • Mark ready when done.
  • 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.
[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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat <question> 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

🟩 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

…eryText

The model template variable's queryText/rawQueryText fallback (target?.rawQueryText ?? target?.queryText)
meant an unescaped queryText would never be caught once both fields existed. Assert both explicitly, and
extend the TemplateVar.query type to declare queryText (missing since #5349 added the field to the JSON).
@JSONbored JSONbored marked this pull request as ready for review July 12, 2026 21:34
@JSONbored JSONbored force-pushed the codex/fix-grafana-sql-injection-vulnerability branch from 13669cc to e721ac6 Compare July 12, 2026 21:34
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.67%. Comparing base (ecb18c1) to head (e721ac6).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5354      +/-   ##
==========================================
- Coverage   94.71%   94.67%   -0.04%     
==========================================
  Files         555      555              
  Lines       44526    44526              
  Branches    14664    14664              
==========================================
- Hits        42172    42155      -17     
- Misses       1619     1636      +17     
  Partials      735      735              
Flag Coverage Δ
shard-1 43.77% <ø> (-0.25%) ⬇️
shard-2 35.22% <ø> (-0.01%) ⬇️
shard-3 32.07% <ø> (+0.06%) ⬆️
shard-4 31.56% <ø> (-0.53%) ⬇️
shard-5 33.12% <ø> (+0.39%) ⬆️
shard-6 43.75% <ø> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes

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

@JSONbored JSONbored merged commit bceff04 into main Jul 12, 2026
17 checks passed
@JSONbored JSONbored deleted the codex/fix-grafana-sql-injection-vulnerability branch July 12, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark codex gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant