diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 6b891bdadf..64413fa74e 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -1500,12 +1500,13 @@ async def update_message_by_id( if user.role != 'admin' and message.user_id != user.id: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) else: - if ( - user.role != 'admin' - and message.user_id != user.id - and not await channel_has_access(user.id, channel, permission='write', strict=False, db=db) + if user.role != 'admin' and not await channel_has_access( + user.id, channel, permission='write', strict=False, db=db ): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) + # Write access is not authorship — block cross-member edits. + if user.role != 'admin' and message.user_id != user.id: + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) try: await Messages.update_message_by_id(message_id, form_data, db=db) @@ -1725,18 +1726,17 @@ async def delete_message_by_id( if user.role != 'admin' and message.user_id != user.id: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) else: - if ( - user.role != 'admin' - and message.user_id != user.id - and not await channel_has_access( - user.id, - channel, - permission='write', - strict=False, - db=db, - ) + if user.role != 'admin' and not await channel_has_access( + user.id, + channel, + permission='write', + strict=False, + db=db, ): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) + # Write access is not authorship — block cross-member deletes. + if user.role != 'admin' and message.user_id != user.id: + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()) try: await Messages.delete_message_by_id(message_id, db=db)