fix(security): harden agent share listing and align full-access API key routes

Enforce tenant ownership in ListSharesByAgent so full-access API keys cannot enumerate cross-tenant shares, and allow full-access keys to create KBs and manage share routes consistently with other tenant-wide operations.
This commit is contained in:
wizardchen
2026-07-13 16:55:35 +08:00
committed by lyingbug
parent 1dfa23d728
commit 50b8c0a72e
7 changed files with 90 additions and 25 deletions
+14 -1
View File
@@ -1356,8 +1356,21 @@ func (h *OrganizationHandler) ShareAgent(c *gin.Context) {
func (h *OrganizationHandler) ListAgentShares(c *gin.Context) {
ctx := c.Request.Context()
agentID := c.Param("id")
shares, err := h.agentShareService.ListSharesByAgent(ctx, agentID)
tenantID := c.GetUint64(types.TenantIDContextKey.String())
if tenantID == 0 {
c.Error(apperrors.NewUnauthorizedError("Unauthorized"))
return
}
shares, err := h.agentShareService.ListSharesByAgent(ctx, agentID, tenantID)
if err != nil {
if errors.Is(err, service.ErrAgentNotFoundForShare) {
c.Error(apperrors.NewNotFoundError("Agent not found"))
return
}
if errors.Is(err, service.ErrNotAgentOwner) {
c.Error(apperrors.NewForbiddenError("Only the agent owner can list its shares"))
return
}
logger.Errorf(ctx, "Failed to list agent shares: %v", err)
c.Error(apperrors.NewInternalServerError("Failed to list shares"))
return