Advanced SQL Analytics Framework

grafana/grafana#94942
Golden recall: 100% Extra findings: 2

Golden Comments (2/2 found)

# Comment Severity Status FriendlyReviewer Detail
#1 The enableSqlExpressions function has flawed logic that always returns false, effectively disabling SQL expressions unconditionally HIGH ✓ Found "Function enableSqlExpressions is dead code with inverted logic and ignores the feature toggle. It always returns false regardless of IsEnabledGlobally, and the local variable enabled is assigned !IsEnabledGlobally(...), meaning it is true when the flag is off. This is confusing and a latent security landmine: a future developer who 'fixes' the function to if enabled { return true } would re-open the CVE-2024-9264 RCE/LFI path" (reader.go L195)
#2 Several methods such as NewInMemoryDB().RunCommands and db.QueryFramesInto return 'not implemented' HIGH ✓ Found "The new DB type and its methods (TablesList, RunCommands, QueryFramesInto, NewInMemoryDB) all fail with 'not implemented' but carry no explanation of why. A future contributor could reasonably 'complete' these stubs with a real backend (e.g., re-introducing go-duck) and silently resurrect the vulnerability" (sql/db.go L24)

Supplementary Findings (2 findings)

Finding File Severity Legitimate?
Dead code in the disabled path: the if frame.Rows() == 0 { rsp.Values = NoData{...} } block is unconditionally overwritten with TableData right after sql_command.go:96 LOW ✓ Real dead code, but pre-existing and inside an otherwise-disabled command — a drive-by cleanup rather than a defect of this PR
Dead DuckDB serialization scaffolding in TablesList (strings.Replace, json_serialize_sql, duckDB.RunCommands) with unreachable helpers tablesFromAST/astError/existsInList parser.go:23 LOW ✓ Borderline: harmless, but makes the code read as though DuckDB parsing still happens — confusing in a security-disable PR

Honest Analysis

FriendlyReviewer found both golden bugs of this PR — recall 100%. On the enableSqlExpressions golden, the review goes beyond the reference comment: it not only establishes that the function always returns false, it explains the inverted logic (enabled is assigned !IsEnabledGlobally(...), true when the flag is off) and names the concrete hazard — a future developer 'fixing' the function to return true when enabled would re-open the CVE-2024-9264 RCE/LFI path, and would do so exactly when the flag is off.

The same depth applies to the second golden: the 'not implemented' stub methods (NewInMemoryDB, RunCommands, QueryFramesInto, TablesList) are identified, and the review connects them to the same re-opening risk — a future contributor 'completing' the stubs with a real backend would silently resurrect the vulnerability. The review also verifies the functional outcome of the security fix: SQL expressions are disabled in all three gates, DuckDB references are removed from go.mod and imports, and no bypass was found. It additionally flags the now-ignored FlagSqlExpressions toggle and the unchecked documentation item.

The two supplementary findings are low-severity cleanup items: dead code in the disabled path of sql_command.go (pre-existing, immediately overwritten) and the dead DuckDB serialization scaffolding in parser.go that makes the code read as though SQL parsing still occurs. Both are legitimate and consistent with the intent of the PR — the review's stance is that anything suggesting DuckDB parsing still happens should be removed. The remaining caveat is inherent to security disablements: 'no bypass found' is verified on the three gates, but nothing here substitutes for a dedicated audit of the disabled paths before the backport is relied upon.

FriendlyReviewer's full review

As posted on the PR — the complete output from FriendlyReviewer.

friendly-reviewer bot commented now

Hi there 👋

🌥️ Tech 🌤️ Feat
1 high, 1 medium, 2 low 2 ok, 2 mitigated

The PR disables SQL expressions to remediate CVE-2024-9264 (RCE/LFI) and removes the DuckDB dependency. The security behavior is correct: SQL expressions are unconditionally disabled in all three gates (reader.go, nodes.go/sql_command.go, and the stub DB layer), and no bypass was found. The removal of the DuckDB import and go.mod entry is complete. However, the implementation introduces several maintainability and security-adjacent concerns that should be cleaned up before merge: the toggle-gating function in reader.go contains dead code with semantically inverted logic that could mislead future contributors into re-enabling the vulnerable path; the stub DB methods lack explanatory comments about why they are disabled; parser.go retains dead DuckDB serialization scaffolding; and there is an unreachable branch in sql_command.go. The documentation checklist item remains unchecked, and the feature toggle is now effectively ignored. These issues are non-blocking for the security fix itself but are recommended for change before final approval.


These might need a close look

  • 🔴 pkg/expr/reader.go (L195)
    Function enableSqlExpressions is dead code with inverted logic and ignores the feature toggle. It always returns false regardless of IsEnabledGlobally, and the local variable enabled is assigned !IsEnabledGlobally(...), meaning it is true when the flag is off. This is confusing and a latent security landmine: a future developer who 'fixes' the function to if enabled { return true } would re-open the CVE-2024-9264 RCE/LFI path, and would enable SQL exactly when the flag is off (inverted). Replace the body with return false plus a comment stating SQL expressions are permanently disabled for security.

Worth checking

  • 🟡 pkg/expr/sql/db.go (L24)
    The new DB type and its methods (TablesList, RunCommands, QueryFramesInto, NewInMemoryDB) all fail with 'not implemented' but carry no explanation of why. A future contributor could reasonably 'complete' these stubs with a real backend (e.g., re-introducing go-duck) and silently resurrect the vulnerability. Add a comment documenting that SQL expression execution is intentionally disabled for CVE-2024-9264 and that a working DuckDB backend must not be wired back in.
Small things (take or leave)
  • 🔵 pkg/expr/sql_command.go (L96)
    In the disabled path, db.QueryFramesInto returns 'not implemented' and sets rsp.Error, which is fine as defense-in-depth. However, the if frame.Rows() == 0 { rsp.Values = NoData{...} } block is dead code because rsp.Values is unconditionally overwritten with TableData right after. This is pre-existing but worth a drive-by cleanup to avoid confusion in an otherwise-disabled command.
  • 🔵 pkg/expr/sql/parser.go (L23)
    TablesList still contains dead DuckDB serialization scaffolding: it performs strings.Replace, builds SELECT json_serialize_sql('%s'), and calls duckDB.RunCommands, all of which funnel into the stub's 'not implemented' error. The helper functions tablesFromAST/astError/existsInList are unreachable. This is not harmful but makes the code read as though DuckDB parsing still happens. Simplify TablesList to return the 'not implemented' error directly to make it unambiguous that no SQL parsing is performed.

✅ Feature-level checklist

Looks good

  • Remove all references to DuckDB from the codebase (go.mod, imports, and code).
    The go-duck dependency is removed from go.mod and imports; only a harmless checksum entry remains in go.work.sum. No remaining duck. usages exist.
  • Disable SQL Expressions to prevent the CVE-2024-9264 RCE/LFI vulnerability.
    SQL expressions are unconditionally disabled in all three independent paths (reader.go, nodes.go/sql_command.go, and the stub DB layer). No bypass was found; the functional outcome is secure.

Partially covered

  • ⚠️ If this is a pre-GA feature, it should be behind a feature toggle.
    The FlagSqlExpressions toggle still exists but is now ignored; enableSqlExpressions always returns false regardless of the flag. While this is acceptable for a security disable, the dead code and inverted logic in reader.go misleadingly suggest the toggle is honored, which could lead to accidental re-enablement. Consider simplifying the code to explicitly state the feature is permanently disabled.
  • ⚠️ The docs should be updated, and if it is a notable improvement, added to What's New.
    The PR description notes the documentation is not being updated in this PR (other than the existing flag mention). This is acceptable for a security backport, but the checklist item remains unchecked and should be addressed in a follow-up to keep the documentation accurate.