fix(router): restrict KB-scoped file proxy to exports/ paths
Borrowers with shared-KB read access could previously request any owner-tenant storage path via /knowledge-bases/:id/files. Limit the proxy to exports/ embedded images; raw knowledge uploads continue to use /knowledge/:id/download.
This commit is contained in:
@@ -92,6 +92,18 @@ func TestValidateStoragePathTenant(t *testing.T) {
|
||||
assert.Error(t, ValidateStoragePathTenant("local://docs/example.txt", 42))
|
||||
}
|
||||
|
||||
func TestValidateKBScopedStoragePath(t *testing.T) {
|
||||
const tenantID uint64 = 10008
|
||||
|
||||
assert.NoError(t, ValidateKBScopedStoragePath("local://10008/exports/img.jpg", tenantID))
|
||||
assert.NoError(t, ValidateKBScopedStoragePath("minio://bucket/10008/exports/uuid.png", tenantID))
|
||||
assert.NoError(t, ValidateKBScopedStoragePath("oss://bucket/exports/10008/uuid.png", tenantID))
|
||||
|
||||
assert.Error(t, ValidateKBScopedStoragePath("local://10008/knowledge-id/123.pdf", tenantID))
|
||||
assert.Error(t, ValidateKBScopedStoragePath("local://9999/exports/img.jpg", tenantID))
|
||||
assert.Error(t, ValidateKBScopedStoragePath("local://10008/other/img.jpg", tenantID))
|
||||
}
|
||||
|
||||
func TestParseTenantIDFromStoragePath(t *testing.T) {
|
||||
tests := []struct {
|
||||
path string
|
||||
|
||||
Reference in New Issue
Block a user