feat(session): implement strict owner scope for API-key sessions

Add GetOwnedSession method to enforce strict ownership checks for session mutations, ensuring tenant admins can read but not modify API-key sessions. Update relevant handlers to utilize this method for operations that alter session data, maintaining security and integrity of API-key sessions.
This commit is contained in:
wizardchen
2026-07-20 19:27:25 +08:00
committed by lyingbug
parent 76a4ffe525
commit 29bec6c613
9 changed files with 95 additions and 12 deletions
+4 -2
View File
@@ -258,8 +258,10 @@ func (h *Handler) StopSession(c *gin.Context) {
return
}
// Verify message belongs to the current tenant
session, err := h.sessionService.GetSession(ctx, sessionID)
// Verify message belongs to the current tenant. Stopping generation mutates
// an in-flight run, so use the strict owner scope: a tenant admin may read an
// API-key session but must not be able to interrupt its (external) API calls.
session, err := h.sessionService.GetOwnedSession(ctx, sessionID)
if err != nil {
logger.ErrorWithFields(ctx, err, map[string]interface{}{
"session_id": sessionID,