Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ACL checks for pagebreak, articles com_content layouts (and their editor XTD buttons) blocking legitimate editors #17854

Merged
merged 14 commits into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions components/com_content/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
$input = JFactory::getApplication()->input;
$user = JFactory::getUser();

if ($input->get('view') === 'article' && $input->get('layout') === 'pagebreak')
{
if (!$user->authorise('core.create', 'com_content'))
{
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning');
$checkCreateEdit = ($input->get('view') === 'articles' && $input->get('layout') === 'modal')
|| ($input->get('view') === 'article' && $input->get('layout') === 'pagebreak');

return;
}
}
elseif ($input->get('view') === 'articles' && $input->get('layout') === 'modal')
if ($checkCreateEdit)
{
if (!$user->authorise('core.create', 'com_content'))
// Can create in any category (component permission) or at least in one category
$canCreateRecords = $user->authorise('core.create', 'com_content')
|| count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;

// Instead of checking edit on all records, we can use **same** check as the form editing view
$values = (array) JFactory::getApplication()->getUserState('com_content.edit.article.id');
$isEditingRecords = count($values);

$hasAccess = $canCreateRecords || $isEditingRecords;
if (!$hasAccess)
{
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning');

Expand Down
40 changes: 26 additions & 14 deletions plugins/editors-xtd/article/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,37 @@ class PlgButtonArticle extends JPlugin
*/
public function onDisplay($name)
{

$input = JFactory::getApplication()->input;
$user = JFactory::getUser();

if ($user->authorise('core.create', 'com_content')
|| $user->authorise('core.edit', 'com_content')
|| $user->authorise('core.edit.own', 'com_content'))
// Can create in any category (component permission) or at least in one category
$canCreateRecords = $user->authorise('core.create', 'com_content')
|| count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;

// Instead of checking edit on all records, we can use **same** check as the form editing view
$values = (array) JFactory::getApplication()->getUserState('com_content.edit.article.id');
$isEditingRecords = count($values);

// This ACL check is probably a double-check (form view already performed checks)
$hasAccess = $canCreateRecords || $isEditingRecords;
if (!$hasAccess)
{
$link = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&'
. JSession::getFormToken() . '=1&editor=' . $name;
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning');
Copy link
Contributor

@ggppdk ggppdk Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not enqueue a messsage here, only execute return
Enqueueing a no access message should only be added when viewing the layout


$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link = $link;
$button->text = JText::_('PLG_ARTICLE_BUTTON_ARTICLE');
$button->name = 'file-add';
$button->options = "{handler: 'iframe', size: {x: 800, y: 500}}";
return;
}

$link = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&'
. JSession::getFormToken() . '=1&editor=' . $name;

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link = $link;
$button->text = JText::_('PLG_ARTICLE_BUTTON_ARTICLE');
$button->name = 'file-add';
$button->options = "{handler: 'iframe', size: {x: 800, y: 500}}";

return $button;
}
}
}
43 changes: 28 additions & 15 deletions plugins/editors-xtd/pagebreak/pagebreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,37 @@ class PlgButtonPagebreak extends JPlugin
*/
public function onDisplay($name)
{
$input = JFactory::getApplication()->input;
$user = JFactory::getUser();

if ($user->authorise('core.create', 'com_content')
|| $user->authorise('core.edit', 'com_content')
|| $user->authorise('core.edit.own', 'com_content'))
// Can create in any category (component permission) or at least in one category
$canCreateRecords = $user->authorise('core.create', 'com_content')
|| count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;

// Instead of checking edit on all records, we can use **same** check as the form editing view
$values = (array) JFactory::getApplication()->getUserState('com_content.edit.article.id');
$isEditingRecords = count($values);

// This ACL check is probably a double-check (form view already performed checks)
$hasAccess = $canCreateRecords || $isEditingRecords;
if (!$hasAccess)
{
JFactory::getDocument()->addScriptOptions('xtd-pagebreak', array('editor' => $name));
$link = 'index.php?option=com_content&view=article&layout=pagebreak&tmpl=component&e_name=' . $name;

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link = $link;
$button->text = JText::_('PLG_EDITORSXTD_PAGEBREAK_BUTTON_PAGEBREAK');
$button->name = 'copy';
$button->options = "{handler: 'iframe', size: {x: 500, y: 300}}";

return $button;
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning');
Copy link
Contributor

@ggppdk ggppdk Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this message should be removed, only execute return


return;
}

JFactory::getDocument()->addScriptOptions('xtd-pagebreak', array('editor' => $name));
$link = 'index.php?option=com_content&view=article&layout=pagebreak&tmpl=component&e_name=' . $name;

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link = $link;
$button->text = JText::_('PLG_EDITORSXTD_PAGEBREAK_BUTTON_PAGEBREAK');
$button->name = 'copy';
$button->options = "{handler: 'iframe', size: {x: 500, y: 300}}";

return $button;
}
}