Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions inc/Smartling/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ private function initRoles(): void
#[NoReturn]
public function updateGlobalExpertSettings(): void
{
check_ajax_referer('smartling_expert_global_settings', '_wpnonce');
if (check_ajax_referer('smartling_expert_global_settings', '_wpnonce', false) === false) {
static::getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_expert_global_settings', get_current_user_id()));
wp_send_json(['error' => 'Invalid nonce'], 403);
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP)) {
static::getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP));
wp_send_json(['error' => 'Insufficient permissions'], 403);
return;
}

$data = $_POST['params'];
Expand Down
9 changes: 8 additions & 1 deletion inc/Smartling/Helpers/UiMessageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

namespace Smartling\Helpers;

use Smartling\Bootstrap;

class UiMessageHelper
{
private const CACHE_KEY_PREFIX = 'smartling.ui.message.';
public const DISMISS_MESSAGE_ACTION = 'smartling_dismiss_message';

public static function dismissMessage(): void
{
check_ajax_referer(self::DISMISS_MESSAGE_ACTION, '_wpnonce');
if (check_ajax_referer(self::DISMISS_MESSAGE_ACTION, '_wpnonce', false) === false) {
Bootstrap::getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', self::DISMISS_MESSAGE_ACTION, get_current_user_id()));
wp_send_json_error(['message' => 'Invalid nonce'], 403);
return;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_MENU_CAP)) {
Bootstrap::getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_MENU_CAP));
wp_send_json_error(['message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
14 changes: 12 additions & 2 deletions inc/Smartling/Services/ContentRelationsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public function register(): void
*/
public function createSubmissionsHandler(array $data = null): void
{
$this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce');
if ($this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_translation', get_current_user_id()));
$this->returnError('invalid.nonce', 'Invalid nonce', 403);
return;
}
if (!$this->wpProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
$this->returnError('permission.denied', 'Insufficient permissions', 403);
return;
}
Expand All @@ -104,8 +109,13 @@ public function createSubmissionsHandler(array $data = null): void

public function actionHandler(): void
{
$this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce');
if ($this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_translation', get_current_user_id()));
$this->returnError('invalid.nonce', 'Invalid nonce', 403);
return;
}
if (!$this->wpProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
$this->returnError('permission.denied', 'Insufficient permissions', 403);
return;
}
Expand Down
7 changes: 6 additions & 1 deletion inc/Smartling/WP/Controller/CheckStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ public function register(): void
*/
public function ajaxHandler()
{
check_ajax_referer('smartling_check_status', '_wpnonce');
if (check_ajax_referer('smartling_check_status', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_check_status', get_current_user_id()));
wp_send_json(['error' => 'Invalid nonce'], 403);
return false;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
wp_send_json(['error' => 'Insufficient permissions'], 403);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ public function register(): void

public function initTestConnectionEndpoint(): void
{
check_ajax_referer('smartling_test_connection', '_wpnonce');
if (check_ajax_referer('smartling_test_connection', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_test_connection', get_current_user_id()));
wp_send_json(['status' => 403, 'message' => 'Invalid nonce'], 403);
return;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP));
wp_send_json(['status' => 403, 'message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
12 changes: 7 additions & 5 deletions inc/Smartling/WP/Controller/ContentEditJobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class ContentEditJobController extends WPAbstract implements WPHookInterface
{
public const SMARTLING_JOB_API_PROXY = 'smartling_job_api_proxy';

private WordpressFunctionProxyHelper $wpProxy;

public function __construct(
ApiWrapperInterface $api,
LocalizationPluginProxyInterface $localizationPluginProxy,
Expand All @@ -37,10 +35,9 @@ public function __construct(
SiteHelper $siteHelper,
SubmissionManager $submissionManager,
Cache $cache,
WordpressFunctionProxyHelper $wpProxy,
private WordpressFunctionProxyHelper $wpProxy,
) {
parent::__construct($api, $localizationPluginProxy, $pluginInfo, $settingsManager, $siteHelper, $submissionManager, $cache);
$this->wpProxy = $wpProxy;
}
/**
* @var string
Expand Down Expand Up @@ -87,8 +84,13 @@ public function setServedContentType($servedContentType)
public function initJobApiProxy(): void
{
add_action('wp_ajax_' . self::SMARTLING_JOB_API_PROXY, function () {
$this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce');
if ($this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_translation', get_current_user_id()));
$this->wpProxy->wp_send_json(['status' => 403, 'message' => 'Invalid nonce'], 403);
return;
}
if (!$this->wpProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
$this->wpProxy->wp_send_json(['status' => 403, 'message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
14 changes: 12 additions & 2 deletions inc/Smartling/WP/Controller/InstantTranslationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public function register(): void

public function handleRequestTranslation(): void
{
$this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce');
if ($this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_translation', get_current_user_id()));
$this->wpProxy->wp_send_json_error(['message' => 'Invalid nonce'], 403);
return;
}

if (!$this->wpProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
$this->wpProxy->wp_send_json_error(['message' => 'Insufficient permissions'], 403);
return;
}
Expand Down Expand Up @@ -139,9 +144,14 @@ public function handleRequestTranslation(): void

public function handlePollStatus(): void
{
$this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce');
if ($this->wpProxy->check_ajax_referer('smartling_translation', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_translation', get_current_user_id()));
$this->wpProxy->wp_send_json_error(['message' => 'Invalid nonce'], 403);
return;
}

if (!$this->wpProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
$this->wpProxy->wp_send_json_error(['message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
7 changes: 6 additions & 1 deletion inc/Smartling/WP/Controller/LiveNotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ public function placeJsConfig(): void

public function deleteNotificationAjaxHandler(): void
{
check_ajax_referer(self::DELETE_NOTIFICATION_ACTION_NAME, '_wpnonce');
if (check_ajax_referer(self::DELETE_NOTIFICATION_ACTION_NAME, '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', self::DELETE_NOTIFICATION_ACTION_NAME, get_current_user_id()));
wp_send_json(['code' => 'error', 'message' => 'Invalid nonce'], 403);
return;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
wp_send_json(['code' => 'error', 'message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
14 changes: 12 additions & 2 deletions inc/Smartling/WP/Controller/PostBasedWidgetControllerStd.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ public function setNoOriginalFound($noOriginalFound)

public function ajaxDownloadHandler(): void
{
check_ajax_referer(self::AJAX_NONCE_ACTION, '_wpnonce');
if (check_ajax_referer(self::AJAX_NONCE_ACTION, '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', self::AJAX_NONCE_ACTION, get_current_user_id()));
wp_send_json(['status' => self::RESPONSE_AJAX_STATUS_FAIL, 'message' => 'Invalid nonce'], 403);
return;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
wp_send_json(['status' => self::RESPONSE_AJAX_STATUS_FAIL, 'message' => 'Insufficient permissions'], 403);
return;
}
Expand Down Expand Up @@ -182,8 +187,13 @@ private function validateTargetBlog($blogId)

public function ajaxUploadHandler()
{
check_ajax_referer(self::AJAX_NONCE_ACTION, '_wpnonce');
if (check_ajax_referer(self::AJAX_NONCE_ACTION, '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', self::AJAX_NONCE_ACTION, get_current_user_id()));
wp_send_json(['status' => self::RESPONSE_AJAX_STATUS_FAIL, 'message' => 'Invalid nonce'], 403);
return;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_WIDGET_CAP));
wp_send_json(['status' => self::RESPONSE_AJAX_STATUS_FAIL, 'message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
7 changes: 6 additions & 1 deletion inc/Smartling/WP/Controller/TaxonomyLinksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ private function getMappedTerms()

public function linkTaxonomies($data)
{
$this->wordpressProxy->check_ajax_referer(self::NONCE_ACTION, '_wpnonce');
if ($this->wordpressProxy->check_ajax_referer(self::NONCE_ACTION, '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', self::NONCE_ACTION, get_current_user_id()));
$this->wordpressProxy->wp_send_json_error(['message' => 'Invalid nonce'], 403);
return;
}
if (!$this->wordpressProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_MENU_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_MENU_CAP));
$this->wordpressProxy->wp_send_json_error(['message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
7 changes: 6 additions & 1 deletion inc/Smartling/WP/Controller/TestRunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ public function getBlogs(): array

public function testRun($data): void
{
check_ajax_referer('smartling_test_run', '_wpnonce');
if (check_ajax_referer('smartling_test_run', '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', 'smartling_test_run', get_current_user_id()));
wp_send_json_error(['message' => 'Invalid nonce'], 403);
return;
}
if (!current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP));
wp_send_json_error(['message' => 'Insufficient permissions'], 403);
return;
}
Expand Down
20 changes: 14 additions & 6 deletions inc/Smartling/WP/Controller/VisualConfiguratorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Smartling\WP\Controller;

use Smartling\Helpers\LoggerSafeTrait;
use Smartling\Helpers\PluginInfo;
use Smartling\Helpers\SmartlingUserCapabilities;
use Smartling\Helpers\WordpressFunctionProxyHelper;
Expand All @@ -12,6 +13,8 @@

class VisualConfiguratorPage extends ControllerAbstract implements WPHookInterface
{
use LoggerSafeTrait;

public const SLUG = 'smartling_visual_configurator';
public const NONCE_ACTION = 'smartling_visual_configurator';
public const ACTION_LIST_RULES = 'smartling_visual_configurator_list_rules';
Expand Down Expand Up @@ -87,7 +90,7 @@ public function enqueue(string $hook): void

public function ajaxListRules(): void
{
if (!$this->verifyNonce()) {
if (!$this->verifyNonceAndCapabilities()) {
return;
}
$this->rulesManager->loadData();
Expand All @@ -100,7 +103,7 @@ public function ajaxListRules(): void

public function ajaxSaveRule(): void
{
if (!$this->verifyNonce()) {
if (!$this->verifyNonceAndCapabilities()) {
return;
}
try {
Expand Down Expand Up @@ -141,7 +144,7 @@ public function ajaxSaveRule(): void

public function ajaxResolveType(): void
{
if (!$this->verifyNonce()) {
if (!$this->verifyNonceAndCapabilities()) {
return;
}
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
Expand All @@ -159,7 +162,7 @@ public function ajaxResolveType(): void

public function ajaxDeleteRule(): void
{
if (!$this->verifyNonce()) {
if (!$this->verifyNonceAndCapabilities()) {
return;
}
$id = isset($_POST['id']) && is_string($_POST['id'])
Expand All @@ -177,10 +180,15 @@ public function ajaxDeleteRule(): void
$this->wpProxy->wp_send_json_success(['id' => $id]);
}

private function verifyNonce(): bool
private function verifyNonceAndCapabilities(): bool
{
$this->wpProxy->check_ajax_referer(self::NONCE_ACTION, '_wpnonce');
if ($this->wpProxy->check_ajax_referer(self::NONCE_ACTION, '_wpnonce', false) === false) {
$this->getLogger()->warning(sprintf('Invalid nonce for action "%s" from userId=%d', self::NONCE_ACTION, get_current_user_id()));
$this->wpProxy->wp_send_json_error(['message' => 'Invalid nonce'], 403);
return false;
}
if (!$this->wpProxy->current_user_can(SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP)) {
$this->getLogger()->warning(sprintf('User %d lacks capability "%s"', get_current_user_id(), SmartlingUserCapabilities::SMARTLING_CAPABILITY_PROFILE_CAP));
$this->wpProxy->wp_send_json_error(['message' => 'Insufficient permissions'], 403);
return false;
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Additional information on the Smartling Connector for WordPress can be found [he

== Changelog ==
= 5.5.2 =
* Added visual configurator for JSON metadata fields
* Added "Check All" and "Uncheck All" buttons to the related assets list

= 5.5.1 =
Expand Down