fix: restrict database query allowed tables

This commit is contained in:
wizardchen
2026-01-26 11:00:35 +08:00
committed by lyingbug
parent 1dd76df261
commit 90ebd492ce
2 changed files with 6 additions and 8 deletions
+1 -1
View File
@@ -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
+5 -7
View File
@@ -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)
}
}