Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/acychecker/acychecker.php
+++ b/acychecker/acychecker.php
@@ -5,7 +5,7 @@
Author: Acyba
Author URI: https://www.acychecker.com
License: GPLv3
-Version: 2.0.0
+Version: 2.0.1
*/
if (!defined('ABSPATH')) {
--- a/acychecker/cms/cmsServices/Database.php
+++ b/acychecker/cms/cmsServices/Database.php
@@ -221,7 +221,7 @@
public static function secureDBColumn($fieldName)
{
if (!is_string($fieldName) || preg_match('|[^a-z0-9#_.-]|i', $fieldName) !== 0) {
- die('field, table or database "'.esc_html($fieldName).'" not secured');
+ throw new InvalidArgumentException('AcyChecker: unsecured database identifier "'.Security::escape(is_string($fieldName) ? $fieldName : gettype($fieldName)).'"');
}
return $fieldName;
--- a/acychecker/cms/cmsServices/File.php
+++ b/acychecker/cms/cmsServices/File.php
@@ -4,49 +4,6 @@
class File
{
- public static function fileGetContent(string $url, int $timeout = 10)
- {
- if (strpos($url, '_custom.ini') !== false && !file_exists($url)) {
- return '';
- }
-
- ob_start();
- $data = '';
-
- if (strpos($url, 'http') === 0 && class_exists('WP_Http') && method_exists('WP_Http', 'request')) {
- $args = ['timeout' => $timeout];
- $request = new WP_Http();
- $data = $request->request($url, $args);
- $data = (empty($data) || !is_array($data) || empty($data['body'])) ? '' : $data['body'];
- }
-
- if (empty($data) && function_exists('file_get_contents')) {
- $options = [
- 'ssl' => [
- 'verify_peer' => false,
- 'verify_peer_name' => false,
- ],
- ];
- if (!empty($timeout)) {
- $options['http']['timeout'] = $timeout;
- }
- $streamContext = stream_context_create($options);
- $data = file_get_contents($url, false, $streamContext);
- }
-
- if (empty($data) && strpos($url, 'http') !== 0) {
- $data = self::getInternalFileContents($url);
- }
-
- $warnings = ob_get_clean();
-
- if (Security::isDebug()) {
- echo esc_html($warnings);
- }
-
- return $data;
- }
-
public static function getInternalFileContents(string $path)
{
global $wp_filesystem;
--- a/acychecker/cms/cmsServices/Security.php
+++ b/acychecker/cms/cmsServices/Security.php
@@ -88,14 +88,28 @@
wp_die();
}
+ /**
+ * Context hint: are we rendering/handling an admin-side request (vs the plugin's
+ * front-end entry point)?
+ * This is NOT an authorization check and must never be used as one
+ *
+ * Use checkAdminAccess() for permission check instead.
+ */
public static function isAdmin()
{
$page = Security::getVar('string', 'page', '');
- if (!empty($page)) {
- return $page !== 'front';
- } else {
- return is_admin();
+ if ($page === 'acychecker_front') {
+ return false;
+ }
+
+ return is_admin();
+ }
+
+ public static function checkAdminAccess()
+ {
+ if (!current_user_can('manage_options')) {
+ self::raiseError(E_ERROR, 403, __('You are not allowed to access this page', 'acychecker'));
}
}
--- a/acychecker/cms/cmsServices/WordPressMenu.php
+++ b/acychecker/cms/cmsServices/WordPressMenu.php
@@ -23,7 +23,7 @@
add_menu_page(
__('Dashboard', 'acychecker'),
'AcyChecker',
- 'read',
+ 'manage_options',
ACYC_COMPONENT.'_dashboard',
[$this, 'router'],
'data:image/svg+xml;base64,'.base64_encode(
@@ -36,7 +36,7 @@
ACYC_COMPONENT.'_dashboard',
__('Clean my database', 'acychecker'),
__('Clean my database', 'acychecker'),
- 'read',
+ 'manage_options',
ACYC_COMPONENT.'_database',
[$this, 'router']
);
@@ -45,7 +45,7 @@
ACYC_COMPONENT.'_dashboard',
__('Block on registration', 'acychecker'),
__('Block on registration', 'acychecker'),
- 'read',
+ 'manage_options',
ACYC_COMPONENT.'_registration',
[$this, 'router']
);
@@ -54,7 +54,7 @@
ACYC_COMPONENT.'_dashboard',
__('Tests', 'acychecker'),
__('Tests', 'acychecker'),
- 'read',
+ 'manage_options',
ACYC_COMPONENT.'_tests',
[$this, 'router']
);
@@ -63,7 +63,7 @@
ACYC_COMPONENT.'_dashboard',
__('Single test', 'acychecker'),
__('Single test', 'acychecker'),
- 'read',
+ 'manage_options',
ACYC_COMPONENT.'_singletest',
[$this, 'router']
);
@@ -72,7 +72,7 @@
ACYC_COMPONENT.'_dashboard',
__('Configuration', 'acychecker'),
__('Configuration', 'acychecker'),
- 'read',
+ 'manage_options',
ACYC_COMPONENT.'_configuration',
[$this, 'router']
);
@@ -86,6 +86,10 @@
public function router()
{
+ if (!current_user_can('manage_options')) {
+ wp_die(esc_html__('Sorry, you are not allowed to access this page.'), '', ['response' => 403]);
+ }
+
new RouterService();
}
}
--- a/acychecker/src/Classes/TestClass.php
+++ b/acychecker/src/Classes/TestClass.php
@@ -187,6 +187,17 @@
Database::query('UPDATE #__acyc_test SET current_step = '.intval(self::STEP['failed']).' WHERE batch_id = '.intval($batchId));
}
+ public function getEmailsByBatch(int $batchId): array
+ {
+ if (empty($batchId)) {
+ return [];
+ }
+
+ $emails = Database::loadResultArray('SELECT `email` FROM #__acyc_test WHERE batch_id = '.intval($batchId));
+
+ return empty($emails) ? [] : $emails;
+ }
+
public function deletePending()
{
return Database::query('DELETE FROM #__acyc_test WHERE current_step = '.intval(self::STEP['pending']));
--- a/acychecker/src/Controllers/CallbackController.php
+++ b/acychecker/src/Controllers/CallbackController.php
@@ -31,6 +31,14 @@
$configUrls = $this->config->get('urls_results_batch', '[]');
$configUrls = json_decode($configUrls, true);
+ $expectedToken = isset($configUrls[$testId]['token']) ? (string)$configUrls[$testId]['token'] : '';
+ $providedToken = (string)Security::getVar('cmd', 'acyc_token', '');
+ if ($expectedToken === '' || $providedToken === '' || !hash_equals($expectedToken, $providedToken)) {
+ DebugService::logMessage('callback_controller.log', 'Rejected callback for batch '.$testId.': missing or invalid authentication token');
+
+ exit;
+ }
+
$testService = new TestService();
$decodedResult = $testService->decodeResult($result);
--- a/acychecker/src/Controllers/DatabaseController.php
+++ b/acychecker/src/Controllers/DatabaseController.php
@@ -120,6 +120,8 @@
protected function store()
{
+ Form::checkToken();
+
$savedConfig = Security::getVar('array', 'acyc_config');
$newConfig = [
'tables_selected' => isset($savedConfig['tables_selected']) ? $savedConfig['tables_selected'] : [],
--- a/acychecker/src/Controllers/TestsController.php
+++ b/acychecker/src/Controllers/TestsController.php
@@ -305,9 +305,16 @@
private function getNumberOfElementsToDisplay()
{
- $selectValue = Security::getVar('int', 'acyc_element_per_page', $this->config->get('listing_element_page', self::DEFAULT_ELEMENTS_PER_PAGE));
+ $storedValue = (int)$this->config->get('listing_element_page', self::DEFAULT_ELEMENTS_PER_PAGE);
- $this->config->save(['listing_element_page' => $selectValue]);
+ $selectValue = Security::getVar('int', 'acyc_element_per_page', null);
+ if ($selectValue === null || $selectValue <= 0) {
+ return $storedValue;
+ }
+
+ if ($selectValue !== $storedValue) {
+ $this->config->save(['listing_element_page' => $selectValue]);
+ }
return $selectValue;
}
@@ -494,7 +501,7 @@
$oneElement->$oneColumn = '';
}
- $line[] = htmlspecialchars($oneElement->$oneColumn, ENT_QUOTES);
+ $line[] = $this->neutralizeCsvValue($oneElement->$oneColumn);
}
fputcsv($output, $line, ',', '"', '');
@@ -509,6 +516,23 @@
exit;
}
+ /**
+ * Neutralize CSV/formula injection: a cell whose first character is one of
+ * = + - @ TAB CR can be executed as a formula by Excel/LibreOffice/Sheets.
+ * Prefix it with a single quote so the spreadsheet treats it as literal text.
+ * CSV-level escaping (commas, quotes, newlines) is handled by fputcsv().
+ */
+ private function neutralizeCsvValue($value): string
+ {
+ $value = (string)$value;
+
+ if ($value !== '' && in_array($value[0], ['=', '+', '-', '@', "t", "r"], true)) {
+ $value = "'".$value;
+ }
+
+ return $value;
+ }
+
private function executeActionOnUsers($action)
{
Form::checkToken();
--- a/acychecker/src/Libraries/AcycController.php
+++ b/acychecker/src/Libraries/AcycController.php
@@ -7,8 +7,6 @@
use AcyCheckerCmsServicesForm;
use AcyCheckerCmsServicesMiscellaneous;
use AcyCheckerCmsServicesRouter;
-use AcyCheckerCmsServicesLanguage;
-use AcyCheckerCmsServicesMessage;
use AcyCheckerCmsServicesSecurity;
use AcyCheckerCmsServicesUrl;
@@ -49,19 +47,6 @@
$this->isAcymailing5Installed = Extension::isExtensionActive($acy5Extension);
}
- public function call($task)
- {
- // If task doesn't exist, redirect to default task + add message
- if (!method_exists($this, $task)) {
- Message::enqueueMessage(__('This page doesn't exist', 'acychecker'), 'warning');
- $task = $this->defaultTask;
- Security::setVar('task', $task);
- }
-
- // Call the task
- $this->$task();
- }
-
public function loadScripts($task)
{
if (empty($this->loadScripts)) return;
@@ -124,13 +109,6 @@
$this->display();
}
- public function apply()
- {
- $this->store();
-
- $this->edit();
- }
-
public function add()
{
Security::setVar('cid', []);
@@ -141,6 +119,8 @@
public function save()
{
+ Form::checkToken();
+
if (method_exists($this, 'store')) {
$this->store();
}
--- a/acychecker/src/Libraries/AcycView.php
+++ b/acychecker/src/Libraries/AcycView.php
@@ -212,11 +212,11 @@
private function loadAssets()
{
$javascript = '
- var ACYC_CMS = "'.ACYC_CMS.'";';
+ var ACYC_CMS = '.json_encode(ACYC_CMS).';';
- if ('joomla' == ACYC_CMS) {
+ if ('joomla' === ACYC_CMS) {
$javascript .= '
- var ACYC_J40 = "'.ACYC_J40.'";';
+ var ACYC_J40 = '.(ACYC_J40 ? 'true' : 'false').';';
}
Router::addScript(true, $javascript);
--- a/acychecker/src/Services/ApiService.php
+++ b/acychecker/src/Services/ApiService.php
@@ -90,7 +90,6 @@
$headers = $headers + $this->getDefaultHeaders();
$options = [
- 'verifySsl' => false,
'headers' => $headers,
'method' => $method,
'data' => $data,
@@ -120,7 +119,7 @@
'Content-Type' => Router::CONTENT_TYPE_JSON,
'API-KEY' => $this->apiKey,
'Source' => 'plugin',
- 'Source-Version' => '2.0.0',
+ 'Source-Version' => '2.0.1',
];
}
@@ -166,9 +165,20 @@
$url = $this->apiBaseUrl.'bulk_verify/';
+ // Generate a per-batch secret token for authentication on public route.
+ // If no secure randomness is available, abort rather than dispatch with a weak token.
+ try {
+ $callbackToken = SecurityService::generateToken();
+ } catch (Exception $e) {
+ DebugService::logMessage('batch_tests.log', 'Could not generate a secure callback token, batch not dispatched');
+
+ return $this->returnResponse(__('Could not generate a secure token, please try again', 'acychecker'), [], false);
+ }
+ $callbackUrl = Url::frontendLink('callbackController').'&acyc_token='.$callbackToken;
+
$data = [
'emails' => $emails,
- 'callbackUrl' => Url::frontendLink('callbackController'),
+ 'callbackUrl' => $callbackUrl,
'fileType' => 'CSV',
];
@@ -195,6 +205,9 @@
return $this->returnResponse($message, [], false);
}
+ // Store callback token for authentication.
+ $request['acyc_callback_token'] = $callbackToken;
+
return $this->returnResponse('', $request);
}
@@ -308,7 +321,7 @@
private function getEmailResult($email)
{
- $url = $this->apiBaseUrl.'email_verify/'.$email;
+ $url = $this->apiBaseUrl.'email_verify/'.rawurlencode($email);
$request = $this->processRequest($url);
@@ -423,7 +436,7 @@
return false;
}
- $url = $this->apiBaseUrl.'bulk_result/'.$batchId;
+ $url = $this->apiBaseUrl.'bulk_result/'.rawurlencode($batchId);
$request = $this->processRequest($url);
--- a/acychecker/src/Services/CronService.php
+++ b/acychecker/src/Services/CronService.php
@@ -288,6 +288,7 @@
'url' => $result['data']['url_result'],
'last_check' => time(),
'attempts' => 0,
+ 'token' => $result['data']['acyc_callback_token'] ?? '',
];
$this->config->save(['urls_results_batch' => json_encode($urlsBatch)]);
--- a/acychecker/src/Services/DebugService.php
+++ b/acychecker/src/Services/DebugService.php
@@ -16,7 +16,7 @@
$result = ob_get_clean();
if ($ajax) {
- file_put_contents(ACYC_BACK.'debug.log', $result, FILE_APPEND);
+ file_put_contents(self::getLogPath('debug.log', true), $result, FILE_APPEND);
} else {
$style = $indent ? 'margin-left: 220px;' : '';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Only for support debug, not used in plugin.
@@ -26,8 +26,9 @@
public static function getLogPath($filename, $create = false)
{
- $reportPath = ACYC_LOGS_FOLDER.$filename;
- $reportPath = File::cleanPath(ACYC_ROOT.trim(html_entity_decode($reportPath)));
+ $filename = basename(trim(html_entity_decode((string)$filename)));
+ $reportPath = File::cleanPath(ACYC_ROOT.ACYC_LOGS_FOLDER.$filename);
+
if ($create) {
FileService::createDir(dirname($reportPath), true, true);
}
@@ -42,8 +43,26 @@
$lr = "rn";
file_put_contents(
$reportPath,
- $lr.DateService::getDate(time()).' - '.$message,
+ $lr.DateService::getDate(time()).' - '.self::maskEmails($message),
FILE_APPEND
);
}
+
+ /**
+ * Redact email addresses in the log file.
+ */
+ private static function maskEmails($message)
+ {
+ if (!is_string($message) || $message === '') {
+ return $message;
+ }
+
+ return preg_replace_callback(
+ '/([a-zA-Z0-9._%+-])[a-zA-Z0-9._%+-]*(@[a-zA-Z0-9.-]+.[a-zA-Z]{2,})/',
+ static function ($matches) {
+ return $matches[1].'***'.$matches[2];
+ },
+ $message
+ );
+ }
}
--- a/acychecker/src/Services/RouterService.php
+++ b/acychecker/src/Services/RouterService.php
@@ -5,6 +5,7 @@
use AcyCheckerCmsServicesLanguage;
+use AcyCheckerCmsServicesMessage;
use AcyCheckerCmsServicesSecurity;
use AcyCheckerCmsServicesUrl;
use AcyCheckerCmsServicesRouter as CmsRouter;
@@ -13,6 +14,8 @@
{
public function __construct()
{
+ Security::checkAdminAccess();
+
$ctrl = Security::getVar('cmd', 'ctrl');
$task = Security::getVar('cmd', 'task');
@@ -51,6 +54,12 @@
$routineService = new RoutineService();
$routineService->checkLostResults();
- $controller->call($task);
+ if (!is_callable([$controller, $task])) {
+ Message::enqueueMessage(__('This page doesn't exist', 'acychecker'), 'warning');
+ $task = $controller->defaultTask;
+ Security::setVar('task', $task);
+ }
+
+ $controller->$task();
}
}
--- a/acychecker/src/Services/SecurityService.php
+++ b/acychecker/src/Services/SecurityService.php
@@ -15,6 +15,15 @@
}
}
+ /**
+ * @throws Exception when no cryptographically secure source is available.
+ * Callers must treat a failure as fatal (do not fall back to a weak token).
+ */
+ public static function generateToken(): string
+ {
+ return bin2hex(random_bytes(32));
+ }
+
public static function noCache()
{
HttpService::header('Cache-Control: no-store, no-cache, must-revalidate');
--- a/acychecker/src/Services/TestService.php
+++ b/acychecker/src/Services/TestService.php
@@ -104,6 +104,28 @@
$apiService = new ApiService();
$results = $result['results'];
+ $batchEmails = $testClass->getEmailsByBatch($testId);
+ if (empty($batchEmails)) {
+ DebugService::logMessage('callback_controller.log', 'No stored emails for the batch ID '.intval($testId).', ignoring callback results');
+ $this->sendNextBatch();
+
+ return;
+ }
+
+ $allowedEmails = array_flip(array_map('strtolower', $batchEmails));
+ $results = array_values(array_filter($results, static function ($oneResult) use ($allowedEmails) {
+ $email = $oneResult[ApiService::API_TEST_KEY_EMAIL] ?? '';
+
+ return is_string($email) && isset($allowedEmails[strtolower($email)]);
+ }));
+
+ if (empty($results)) {
+ DebugService::logMessage('callback_controller.log', 'No result matched the emails of the batch ID '.intval($testId));
+ $this->sendNextBatch();
+
+ return;
+ }
+
$allTests = [];
foreach ($results as $oneResult) {
@@ -167,7 +189,13 @@
private function insertTestResult($tests)
{
$firstResult = array_shift($tests);
- $columns = array_keys($firstResult);
+
+ $updates = [];
+ $columns = [];
+ foreach (array_keys($firstResult) as $oneColumn) {
+ $columns[] = Database::secureDBColumn($oneColumn);
+ $updates[] = $oneColumn.' = VALUES('.$oneColumn.')';
+ }
$insertQuery = 'INSERT INTO #__acyc_test ('.implode(', ', $columns).') VALUES ';
$insertQuery .= '('.implode(',', array_values($firstResult)).')';
@@ -176,10 +204,7 @@
$insertQuery .= ',('.implode(',', array_values($values)).')';
}
- foreach ($columns as $i => $oneColumn) {
- $columns[$i] = $oneColumn.' = VALUES('.$oneColumn.')';
- }
- $insertQuery .= ' ON DUPLICATE KEY UPDATE '.implode(', ', $columns);
+ $insertQuery .= ' ON DUPLICATE KEY UPDATE '.implode(', ', $updates);
try {
// We execute the query to store the email tested
--- a/acychecker/src/Services/UpdateService.php
+++ b/acychecker/src/Services/UpdateService.php
@@ -12,7 +12,7 @@
class UpdateService
{
private $cms = 'wordpress';
- private $version = '2.0.0';
+ private $version = '2.0.1';
private $update = false;
private $fromVersion = '';
--- a/acychecker/src/Views/Configuration/default_global.php
+++ b/acychecker/src/Views/Configuration/default_global.php
@@ -10,10 +10,11 @@
<div class="cell grid-x acyc_vcenter margin-y">
<label class="cell medium-3 large-2" for="acyc__configuration__license__input"><?php echo esc_attr(__('License key', 'acychecker')); ?></label>
<div class="cell medium-9 large-10">
- <input type="text"
+ <input type="password"
id="acyc__configuration__license__input"
class="acyc__configuration__text__input"
name="config[license_key]"
+ autocomplete="off"
value="<?php echo esc_attr($this->data['licenseKey']); ?>">
</div>
--- a/acychecker/vendor/composer/installed.php
+++ b/acychecker/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'acyba/acychecker',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
- 'reference' => 'f0e8512f0577c05e2784a3062c8978871ed86031',
+ 'reference' => 'bc64d0bae93e4df97882f04715e0fa183ad3e05a',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -13,7 +13,7 @@
'acyba/acychecker' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
- 'reference' => 'f0e8512f0577c05e2784a3062c8978871ed86031',
+ 'reference' => 'bc64d0bae93e4df97882f04715e0fa183ad3e05a',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),