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
+5 -2
View File
@@ -127,8 +127,11 @@ func (h *Handler) parseQARequest(c *gin.Context, logPrefix string) (*qaRequestCo
logPrefix, sessionID, secutils.SanitizeForLog(secutils.CompactImageDataURLForLog(string(requestJSON))))
}
// Get session
session, err := h.sessionService.GetSession(ctx, sessionID)
// Get session. QA writes new messages into the session, so use the strict
// owner scope: a tenant admin may read an API-key session but must not be
// able to post messages to it (which would otherwise fail later at message
// creation with a 500 instead of a clean not-found).
session, err := h.sessionService.GetOwnedSession(ctx, sessionID)
if err != nil {
logger.Errorf(ctx, "Failed to get session, session ID: %s, error: %v", sessionID, err)
return nil, nil, errors.NewNotFoundError("Session not found")