Skip to content

Commit

Permalink
Improves efficiency in showAttachments() perms checks
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
  • Loading branch information
Sesquipedalian committed May 2, 2022
1 parent 5d2711d commit da1941f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/Profile-Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,10 @@ function export_attachment($uid)
// Try to avoid collisons when attachment names are not unique.
$context['prepend_attachment_id'] = true;

// Allow access to their attachments even if they can't see the board.
// This is just like what we do with posts during export.
$context['attachment_allow_hidden_boards'] = true;

// We should now have what we need to serve the file.
require_once($sourcedir . DIRECTORY_SEPARATOR . 'ShowAttachments.php');
showAttachment();
Expand Down
18 changes: 17 additions & 1 deletion Sources/ShowAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ function showAttachment()
cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
}

// Can they see attachments on this board?
if (!empty($file['id_msg']))
{
// Special case for profile exports.
if (!empty($context['attachment_allow_hidden_boards']))
{
$boards_allowed = array(0);
}
// Check permissions and board access.
elseif (($boards_allowed = cache_get_data('view_attachment_boards_id-' . $user_info['id'])) == null)
{
$boards_allowed = boardsAllowedTo('view_attachments');
cache_put_data('view_attachment_boards_id-' . $user_info['id'], $boards_allowed, mt_rand(850, 900));
}
}

// No access if you don't have permission to see this attachment.
if
(
Expand All @@ -185,7 +201,7 @@ function showAttachment()
!empty($file['id_msg'])
&& (
empty($file['id_board'])
|| !allowedTo('view_attachments', $file['id_board'])
|| ($boards_allowed !== array(0) && !in_array($file['id_board'], $boards_allowed))
)
)
)
Expand Down

0 comments on commit da1941f

Please sign in to comment.