fix(api): reject alt text edits on forwarded messages (#1739)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-19 12:41:07 +02:00
1 parent 8836565c32
commit a81b1abec7
2 files changed
+2 -13

No files matched your search

@@ -93,20 +93,8 @@ export class MessageEditService {
assertGuildMemberCanCommunicate(member); assertGuildMemberCanCommunicate(member);
} }
if (data.message_snapshots !== undefined) { if (data.message_snapshots !== undefined) {
const isAuthor = message.authorId === userId;
const canManage = isAuthor ? true : await hasPermission(Permissions.MANAGE_MESSAGES);
if (!isAuthor && !canManage) {
throw new MissingPermissionsError(); throw new MissingPermissionsError();
} }
const updatedMessage = await this.withMessageLock(channelId, messageId, () =>
this.deps.persistenceService.updateSnapshotAttachments({
message,
snapshotEdits: data.message_snapshots ?? [],
}),
);
await this.deps.dispatchService.dispatchMessageUpdate({channel, message: updatedMessage, requestCache});
return updatedMessage;
}
const user = await this.deps.userRepository.findUnique(userId); const user = await this.deps.userRepository.findUnique(userId);
this.deps.validationService.validateMessageEditable(message); this.deps.validationService.validateMessageEditable(message);
this.deps.validationService.validateMessageContent(data, user, { this.deps.validationService.validateMessageContent(data, user, {
@@ -570,6 +570,7 @@ export function useMediaMenuData(props: MediaMenuDataProps, options: MediaMenuDa
const canManageMessages = Permission.can(Permissions.MANAGE_MESSAGES, {channelId: message.channelId}); const canManageMessages = Permission.can(Permissions.MANAGE_MESSAGES, {channelId: message.channelId});
const canEditAltText = useMemo(() => { const canEditAltText = useMemo(() => {
if (!attachmentId) return false; if (!attachmentId) return false;
if (snapshotIndex !== undefined || message.messageSnapshots) return false;
const attachmentSource = snapshotAttachments ?? message.attachments; const attachmentSource = snapshotAttachments ?? message.attachments;
const attachment = attachmentSource.find((att) => att.id === attachmentId); const attachment = attachmentSource.find((att) => att.id === attachmentId);
const mimeType = attachment?.content_type?.toLowerCase() ?? ''; const mimeType = attachment?.content_type?.toLowerCase() ?? '';
@@ -577,7 +578,7 @@ export function useMediaMenuData(props: MediaMenuDataProps, options: MediaMenuDa
if (!canEditMedia) return false; if (!canEditMedia) return false;
const isMessageAuthor = currentUserId === message.author?.id; const isMessageAuthor = currentUserId === message.author?.id;
return isMessageAuthor || canManageMessages; return isMessageAuthor || canManageMessages;
}, [attachmentId, canManageMessages, currentUserId, message, snapshotAttachments]); }, [attachmentId, canManageMessages, currentUserId, message, snapshotAttachments, snapshotIndex]);
const handleAddToFavorites = useCallback(() => { const handleAddToFavorites = useCallback(() => {
ModalCommands.pushAfterBottomSheetClose( ModalCommands.pushAfterBottomSheetClose(
onClose, onClose,