Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2025-03-09 - SQL Injection in Dynamic Table Names
**Vulnerability:** The pgvector client was constructing SQL queries by directly substituting the configured table name via `fmt.Sprintf` without prior validation. Because table names cannot be parameterized in SQL, this allows SQL injection if the table name originates from an untrusted configuration source.
**Learning:** Even internal configuration values used as SQL identifiers (like table names) must be strictly validated against an allowed character set, especially when dynamic queries are built using `fmt.Sprintf`.
**Prevention:** Always validate SQL identifiers using strict regular expressions (e.g., allowing only alphanumeric characters, underscores, and periods for schema-qualified names) before embedding them into SQL query strings.
6 changes: 6 additions & 0 deletions internal/memory/pgvector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"regexp"
"strings"
"time"

Expand All @@ -26,6 +27,11 @@ func NewClient(cfg config.PgvectorConfig) (*Client, error) {
return nil, fmt.Errorf("pgvector: PGVECTOR_URL is required")
}

validTable := regexp.MustCompile(`^[a-zA-Z0-9_.]+$`)
if !validTable.MatchString(cfg.Table) {
return nil, fmt.Errorf("pgvector: invalid table name")
}

db, err := sql.Open("postgres", cfg.URL)
if err != nil {
return nil, fmt.Errorf("pgvector: open db: %w", err)
Expand Down
Loading