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:
@@ -20,7 +20,9 @@ import (
|
||||
func (h *Handler) UploadTemporaryDocument(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
sessionID := c.Param("session_id")
|
||||
if _, err := h.sessionService.GetSession(ctx, sessionID); err != nil {
|
||||
// Uploading attaches content to the session, so use the strict owner scope:
|
||||
// a tenant admin may read an API-key session but must not add attachments.
|
||||
if _, err := h.sessionService.GetOwnedSession(ctx, sessionID); err != nil {
|
||||
c.Error(apperrors.NewNotFoundError("Session not found"))
|
||||
return
|
||||
}
|
||||
@@ -163,7 +165,9 @@ func (h *Handler) PreviewTemporaryDocument(c *gin.Context) {
|
||||
func (h *Handler) DeleteTemporaryDocument(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
sessionID := sessionIDParam(c)
|
||||
if _, err := h.sessionService.GetSession(ctx, sessionID); err != nil {
|
||||
// Deleting mutates the session's attachments, so use the strict owner scope:
|
||||
// a tenant admin may read an API-key session but must not remove attachments.
|
||||
if _, err := h.sessionService.GetOwnedSession(ctx, sessionID); err != nil {
|
||||
c.Error(apperrors.NewNotFoundError("Session not found"))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user