Skip to content

Commit a4561d7

Browse files
committed
Security: Add filter on messages forwarding
1 parent 3d27597 commit a4561d7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: main/inc/lib/message.lib.php

+20
Original file line numberDiff line numberDiff line change
@@ -3486,4 +3486,24 @@ private static function addTagsFormToSearch(FormValidator $form)
34863486
->setMultiple(true)
34873487
;
34883488
}
3489+
3490+
/**
3491+
* Reports whether the given user is sender or receiver of the given message
3492+
* @param int $userId
3493+
* @param int $messageId
3494+
* @return bool
3495+
*/
3496+
public static function isUserOwner(int $userId, int $messageId)
3497+
{
3498+
$table = Database::get_main_table(TABLE_MESSAGE);
3499+
$sql = "SELECT id FROM $table
3500+
WHERE id = $messageId
3501+
AND (user_receiver_id = $userId OR user_sender_id = $userId)";
3502+
$res = Database::query($sql);
3503+
if (Database::num_rows($res) === 1) {
3504+
return true;
3505+
}
3506+
3507+
return false;
3508+
}
34893509
}

Diff for: main/messages/new_message.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '', $tpl
226226
);
227227
}
228228

229-
if (isset($_GET['forward_id'])) {
229+
if (isset($_GET['forward_id']) && MessageManager::isUserOwner(api_get_user_id(), (int) $_GET['forward_id'])) {
230230
$forwardId = (int) $_GET['forward_id'];
231231
$message_reply_info = MessageManager::get_message_by_id($forwardId);
232232
$attachments = MessageManager::getAttachmentLinkList($forwardId, MessageManager::MESSAGE_TYPE_INBOX);

0 commit comments

Comments
 (0)