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
+27
View File
@@ -0,0 +1,27 @@
package handler
import (
"context"
apperrors "github.com/Tencent/WeKnora/internal/errors"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/utils"
)
// requireTaskProgressTenant ensures async task progress endpoints only
// return data for tasks created under the caller's tenant. Cross-tenant
// probes are hidden as not-found to avoid confirming task existence.
func requireTaskProgressTenant(ctx context.Context, taskID string) error {
taskTenantID, err := utils.TaskTenantID(taskID)
if err != nil {
return apperrors.NewBadRequestError("invalid task ID")
}
callerTenantID, ok := types.TenantIDFromContext(ctx)
if !ok || callerTenantID == 0 {
return apperrors.NewUnauthorizedError("Unauthorized")
}
if taskTenantID != callerTenantID {
return apperrors.NewNotFoundError("task not found")
}
return nil
}