Skip to content

Conversation

@akshayutture-augment
Copy link

… vulnerability (#94942)

* disable sql expressions

remove duckdb ref

* Run `make update-workspace`

---------

Co-authored-by: Scott Lepper <[email protected]>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@akshayutture-augment
Copy link
Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Nov 14, 2025

Greptile Overview

Confidence Score: 2/5

  • This PR addresses a critical security vulnerability but contains broken logic that could cause confusion
  • The security goal (removing DuckDB to prevent RCE/LFI) is achieved, but the broken enableSqlExpressions logic makes the implementation unreliable. The function always returns false regardless of the feature flag state, which happens to disable SQL expressions correctly but for the wrong reason. This creates technical debt and confusion.
  • Pay close attention to pkg/expr/reader.go (broken feature flag logic) and pkg/expr/sql/db.go (stub implementation that will cause runtime errors if invoked)

Important Files Changed

File Analysis

Filename Score Overview
pkg/expr/reader.go 1/5 Added SQL expressions feature gating with broken logic - enableSqlExpressions always returns false
pkg/expr/sql/db.go 0/5 Created stub DB implementation with all methods returning "not implemented" errors, will cause runtime failures
pkg/expr/sql/parser.go 1/5 Updated to use new stub DB implementation instead of go-duck, calls will fail at runtime
pkg/expr/sql_command.go 1/5 Replaced DuckDB with stub implementation that returns errors, SQL queries will always fail

Sequence Diagram

sequenceDiagram
    participant User
    participant ExpressionQueryReader
    participant SQLCommand
    participant DB as sql.DB (Stub)
    participant Parser as sql.Parser

    User->>ExpressionQueryReader: ReadQuery(QueryTypeSQL)
    ExpressionQueryReader->>ExpressionQueryReader: enableSqlExpressions()
    Note over ExpressionQueryReader: Always returns false<br/>(broken logic)
    ExpressionQueryReader-->>User: Error: "sqlExpressions is not implemented"
    
    Note over User,Parser: If feature flag check was fixed:
    
    User->>SQLCommand: NewSQLCommand(refID, rawSQL)
    SQLCommand->>Parser: TablesList(rawSQL)
    Parser->>DB: NewInMemoryDB()
    activate DB
    Parser->>DB: RunCommands([cmd])
    DB-->>Parser: Error: "not implemented"
    deactivate DB
    Parser-->>SQLCommand: Error
    SQLCommand-->>User: Error: "error serializing sql"
    
    User->>SQLCommand: Execute(ctx, now, vars)
    SQLCommand->>DB: NewInMemoryDB()
    activate DB
    SQLCommand->>DB: QueryFramesInto(refID, query, frames, frame)
    DB-->>SQLCommand: Error: "not implemented"
    deactivate DB
    SQLCommand-->>User: Results with error
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +194 to +200
func enableSqlExpressions(h *ExpressionQueryReader) bool {
enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
if enabled {
return false
}
return false
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: enableSqlExpressions always returns false - the logic is broken

The function negates the feature flag check then returns false regardless. This means SQL expressions will ALWAYS be disabled, even if the feature flag is enabled. The logic should be:

Suggested change
func enableSqlExpressions(h *ExpressionQueryReader) bool {
enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
if enabled {
return false
}
return false
}
func enableSqlExpressions(h *ExpressionQueryReader) bool {
return h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/expr/reader.go
Line: 194:200

Comment:
**logic:** `enableSqlExpressions` always returns `false` - the logic is broken

The function negates the feature flag check then returns false regardless. This means SQL expressions will ALWAYS be disabled, even if the feature flag is enabled. The logic should be:

```suggestion
func enableSqlExpressions(h *ExpressionQueryReader) bool {
	return h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
}
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +12 to +22
func (db *DB) TablesList(rawSQL string) ([]string, error) {
return nil, errors.New("not implemented")
}

func (db *DB) RunCommands(commands []string) (string, error) {
return "", errors.New("not implemented")
}

func (db *DB) QueryFramesInto(name string, query string, frames []*data.Frame, f *data.Frame) error {
return errors.New("not implemented")
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: All DB methods return "not implemented" errors

The DB struct methods are stubs that will cause runtime failures. TablesList, RunCommands, and QueryFramesInto all return "not implemented" errors, but parser.go:23 and sql_command.go:96-100 call these methods expecting them to work.

Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/expr/sql/db.go
Line: 12:22

Comment:
**logic:** All DB methods return "not implemented" errors

The `DB` struct methods are stubs that will cause runtime failures. `TablesList`, `RunCommands`, and `QueryFramesInto` all return "not implemented" errors, but `parser.go:23` and `sql_command.go:96-100` call these methods expecting them to work.

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants