Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix: restrict database query allowed tables

wizardchen90ebd492ce15
diff --git a/internal/agent/tools/database_query.go b/internal/agent/tools/database_query.go
index 8c9bbf84b..90ec73f2c 100644
--- a/internal/agent/tools/database_query.go
+++ b/internal/agent/tools/database_query.go
@@ -19,7 +19,7 @@ var databaseQueryTool = BaseTool{
## Security Features
- Automatic tenant_id injection: All queries are automatically filtered by the logged-in user's tenant_id
- Read-only queries: Only SELECT statements are allowed
-- Safe tables: Only allow queries on authorized tables
+- Safe tables: Only allow queries on authorized tables (knowledge_bases, knowledges, chunks)
## Available Tables and Columns
diff --git a/internal/utils/inject.go b/internal/utils/inject.go
index 6435e3e45..521fb333e 100644
--- a/internal/utils/inject.go
+++ b/internal/utils/inject.go
@@ -559,11 +559,11 @@ func WithTenantIsolation(tenantID uint64, tables ...string) SQLValidationOption
v.tablesWithTenantID = make(map[string]bool)
if len(tables) == 0 {
// Default tables with tenant_id
+ // SECURITY: All tables with tenant_id column must be listed here
+ // to ensure proper tenant isolation and prevent cross-tenant data access
v.tablesWithTenantID = map[string]bool{
- "tenants": true,
"knowledge_bases": true,
"knowledges": true,
- "sessions": true,
"chunks": true,
}
} else {
@@ -590,15 +590,13 @@ func WithSecurityDefaults(tenantID uint64) SQLValidationOption {
WithTenantIsolation(tenantID)(v)
// Default allowed tables
+ // SECURITY: Only tables with tenant_id column should be listed here
+ // Tables without tenant_id (messages, embeddings) are excluded to prevent
+ // cross-tenant data access vulnerabilities (CVE: Broken Access Control)
WithAllowedTables(
- "tenants",
"knowledge_bases",
"knowledges",
- "sessions",
- "messages",
"chunks",
- "embeddings",
- "models",
)(v)
}
}