fix: restrict database query allowed tables
This commit is contained in:
@@ -19,7 +19,7 @@ var databaseQueryTool = BaseTool{
|
|||||||
## Security Features
|
## Security Features
|
||||||
- Automatic tenant_id injection: All queries are automatically filtered by the logged-in user's tenant_id
|
- 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
|
- 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
|
## Available Tables and Columns
|
||||||
|
|
||||||
|
|||||||
@@ -559,11 +559,11 @@ func WithTenantIsolation(tenantID uint64, tables ...string) SQLValidationOption
|
|||||||
v.tablesWithTenantID = make(map[string]bool)
|
v.tablesWithTenantID = make(map[string]bool)
|
||||||
if len(tables) == 0 {
|
if len(tables) == 0 {
|
||||||
// Default tables with tenant_id
|
// 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{
|
v.tablesWithTenantID = map[string]bool{
|
||||||
"tenants": true,
|
|
||||||
"knowledge_bases": true,
|
"knowledge_bases": true,
|
||||||
"knowledges": true,
|
"knowledges": true,
|
||||||
"sessions": true,
|
|
||||||
"chunks": true,
|
"chunks": true,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -590,15 +590,13 @@ func WithSecurityDefaults(tenantID uint64) SQLValidationOption {
|
|||||||
WithTenantIsolation(tenantID)(v)
|
WithTenantIsolation(tenantID)(v)
|
||||||
|
|
||||||
// Default allowed tables
|
// 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(
|
WithAllowedTables(
|
||||||
"tenants",
|
|
||||||
"knowledge_bases",
|
"knowledge_bases",
|
||||||
"knowledges",
|
"knowledges",
|
||||||
"sessions",
|
|
||||||
"messages",
|
|
||||||
"chunks",
|
"chunks",
|
||||||
"embeddings",
|
|
||||||
"models",
|
|
||||||
)(v)
|
)(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user