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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user