fix(security): enforce KB access on wiki reads and related IDOR paths

Gate wiki GET routes and initialization config reads with KBAccessRead,
and bind async task progress endpoints to the caller tenant via task ID
parsing. Closes cross-tenant read paths reported in GHSA-ph8f-4qwx-89rr
and related initialization/progress leaks.
This commit is contained in:
wizardchen
2026-07-02 11:59:50 +08:00
committed by lyingbug
parent ab790bcbd9
commit a17a2250ed
9 changed files with 297 additions and 35 deletions
+34
View File
@@ -0,0 +1,34 @@
package utils
import "testing"
func TestParseTaskID_CompoundTaskType(t *testing.T) {
taskID := GenerateTaskID("faq_import", 42, "kb-abc-123")
taskType, tenantID, _, uuidPart, businessID, err := ParseTaskID(taskID)
if err != nil {
t.Fatalf("ParseTaskID failed: %v", err)
}
if taskType != "faq_import" {
t.Fatalf("taskType = %q, want faq_import", taskType)
}
if tenantID != 42 {
t.Fatalf("tenantID = %d, want 42", tenantID)
}
if uuidPart == "" {
t.Fatal("expected uuid part")
}
if businessID == "" {
t.Fatal("expected business ID")
}
}
func TestTaskTenantID(t *testing.T) {
taskID := GenerateTaskID("kb_clone", 7, "source-kb")
got, err := TaskTenantID(taskID)
if err != nil {
t.Fatalf("TaskTenantID failed: %v", err)
}
if got != 7 {
t.Fatalf("TaskTenantID = %d, want 7", got)
}
}