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:
wizardchen
2026-07-13 12:12:09 +08:00
committed by lyingbug
parent 800cea0826
commit def92bb74f
4 changed files with 91 additions and 3 deletions
+12
View File
@@ -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