Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/woocommerce-mercadopago/build/custom.block.asset.php
+++ b/woocommerce-mercadopago/build/custom.block.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-settings', 'wp-data', 'wp-element', 'wp-html-entities'), 'version' => '7e8337dcc93dac2aae14');
+<?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-settings', 'wp-data', 'wp-element', 'wp-html-entities'), 'version' => '85107ec3fd0107e425de');
--- a/woocommerce-mercadopago/src/Admin/Settings.php
+++ b/woocommerce-mercadopago/src/Admin/Settings.php
@@ -34,6 +34,8 @@
private const NONCE_ID = 'mp_settings_nonce';
+ private const DOWNLOAD_LOG_NONCE_ID = 'mp_download_log_nonce';
+
private const ONBOARDING_ERROR = 'onboarding_error';
private const NOT_LINKED_FAILED = 'not_linked_failed';
@@ -291,7 +293,7 @@
'woocommerce',
'Mercado Pago Settings',
'Mercado Pago',
- 'manage_options',
+ 'manage_woocommerce',
'mercadopago-settings',
[$this, 'mercadoPagoSubmenuPageCallback']
);
@@ -342,6 +344,8 @@
$credentialsState = $this->credentialsStates->getCredentialsTemplate($this->getMercadoPagoCredentialsStatus());
+ $downloadLogNonce = $this->nonce->generateNonce(self::DOWNLOAD_LOG_NONCE_ID);
+
include dirname(__FILE__) . '/../../templates/admin/settings/settings.php';
}
@@ -676,6 +680,7 @@
public function mercadopagoDownloadLog()
{
try {
+ $this->nonce->validateNonce(self::DOWNLOAD_LOG_NONCE_ID, Form::sanitizedGetData('nonce'));
$this->downloader->downloadLog();
} catch (Exception $e) {
$this->logs->file->error('Mercado pago gave error to download log files: ' . $e->getMessage(), __CLASS__);
--- a/woocommerce-mercadopago/src/Gateways/CustomGateway.php
+++ b/woocommerce-mercadopago/src/Gateways/CustomGateway.php
@@ -1491,8 +1491,13 @@
'raw_url' => $this->mercadopago->helpers->url->getMercadoPagoSdkUrl(),
],
[
+ 'handle' => 'wc_mercadopago_custom_card_form_error_codes',
+ 'path' => 'checkouts/custom/entities/mp-card-form-error-codes',
+ ],
+ [
'handle' => 'wc_mercadopago_custom_card_form',
'path' => 'checkouts/custom/entities/card-form',
+ 'deps' => ['wc_mercadopago_custom_card_form_error_codes'],
'localize' => [
'security_code_placeholder_text_3_digits' => $this->storeTranslations['security_code_placeholder_text_3_digits'],
],
--- a/woocommerce-mercadopago/src/Gateways/PixGateway.php
+++ b/woocommerce-mercadopago/src/Gateways/PixGateway.php
@@ -532,9 +532,10 @@
'wc_mercadopago_pix_pooling',
$scriptUrl,
[
- 'order_id' => $order->get_id(),
- 'ajax_url' => WC_AJAX::get_endpoint(self::PIX_PAYMENT_STATUS_ENDPOINT),
- 'nonce' => wp_create_nonce(self::PIX_STATUS_NONCE)
+ 'order_id' => $order->get_id(),
+ 'order_key' => $order->get_order_key(),
+ 'ajax_url' => WC_AJAX::get_endpoint(self::PIX_PAYMENT_STATUS_ENDPOINT),
+ 'nonce' => wp_create_nonce(self::PIX_STATUS_NONCE)
]
);
}
@@ -604,18 +605,47 @@
*/
private function getOrderFromRequest(): WC_Order
{
- $orderId = Form::sanitizedPostData('order_id');
- $order = wc_get_order($orderId);
+ $orderId = Form::sanitizedPostData('order_id');
+ $orderKey = Form::sanitizedPostData('order_key');
+ $order = wc_get_order($orderId);
if (!$order) {
- wp_send_json_error(['message' => 'Order not found'], 404);
- throw new Exception('Order not found');
+ $this->rejectPixStatusRequest('order_not_found');
+ }
+
+ $orderKey = is_string($orderKey) ? $orderKey : '';
+
+ if (!$orderKey || !hash_equals($order->get_order_key(), $orderKey)) {
+ $this->rejectPixStatusRequest(!$orderKey ? 'missing_order_key' : 'invalid_order_key');
}
return $order;
}
/**
+ * Reject a Pix status request with a uniform 403 so a caller cannot tell an
+ * absent order from a wrong key; the real reason is recorded only server-side.
+ *
+ * @param string $reason
+ * @return never
+ * @throws Exception
+ */
+ private function rejectPixStatusRequest(string $reason): void
+ {
+ try {
+ $this->datadog->sendEvent('pix_status_access', $reason, null, 'pix', [
+ 'site_id' => $this->mercadopago->sellerConfig->getSiteId(),
+ 'environment' => $this->mercadopago->storeConfig->isTestMode() ? 'homol' : 'prod',
+ 'cust_id' => $this->mercadopago->sellerConfig->getCustIdFromAT(),
+ ]);
+ } catch (Throwable $telemetryFailure) {
+ // Telemetry must never prevent the 403 that blocks the request.
+ }
+ wp_send_json_error(['message' => 'Forbidden'], 403);
+ throw new Exception('Pix status request rejected: ' . $reason);
+ }
+
+ /**
* Get payment ID from order metadata
*
* @param WC_Order $order
--- a/woocommerce-mercadopago/src/Helpers/CurrentUser.php
+++ b/woocommerce-mercadopago/src/Helpers/CurrentUser.php
@@ -115,15 +115,13 @@
}
/**
- * Validate if user has administrator or editor permissions
+ * Validate that the current user has the manage_woocommerce capability
*
* @return void
*/
public function validateUserNeededPermissions(): void
{
- $neededRoles = ['administrator', 'manage_woocommerce'];
-
- if (!$this->userHasRoles($neededRoles)) {
+ if (!$this->currentUserCan('manage_woocommerce')) {
$this->logs->file->error('User does not have permissions', __CLASS__);
wp_send_json_error('Forbidden', 403);
}
--- a/woocommerce-mercadopago/src/Helpers/ErrorMessages.php
+++ b/woocommerce-mercadopago/src/Helpers/ErrorMessages.php
@@ -253,6 +253,7 @@
"Installments attribute must be numeric" => $this->storeTranslations->checkoutErrorMessages['invalid_installments'],
"Not found card on whitelist" => $this->storeTranslations->checkoutErrorMessages['card_not_whitelisted'],
"Not found payment_method" => $this->storeTranslations->checkoutErrorMessages['payment_method_unavailable'],
+ "bin_not_found" => $this->storeTranslations->checkoutErrorMessages['card_details_incorrect'],
];
}
--- a/woocommerce-mercadopago/src/Helpers/MetricContext.php
+++ b/woocommerce-mercadopago/src/Helpers/MetricContext.php
@@ -8,7 +8,7 @@
class MetricContext
{
- public static function buildApiErrorDetails(string $apiRoute, ?object $mercadopago = null): array
+ public static function buildBaseMetricDetails(string $apiRoute, ?object $mercadopago = null): array
{
$details = [
'team' => 'big',
--- a/woocommerce-mercadopago/src/Helpers/Requester.php
+++ b/woocommerce-mercadopago/src/Helpers/Requester.php
@@ -121,7 +121,7 @@
// $status = 0 is the convention for pre-response exceptions (connection/timeout); >= 400 for HTTP error responses.
private function sendApiErrorMetric(string $uri, int $status, string $message): void
{
- $details = MetricContext::buildApiErrorDetails($uri);
+ $details = MetricContext::buildBaseMetricDetails($uri);
$this->datadog->sendEvent('mp_api_error', (string) $status, $message, null, $details);
}
--- a/woocommerce-mercadopago/src/Helpers/Template.php
+++ b/woocommerce-mercadopago/src/Helpers/Template.php
@@ -13,7 +13,7 @@
*/
public static function render(string $template, array $args = []): void
{
- wc_get_template(static::templateName($template), $args, null, Paths::templatesPath());
+ wc_get_template(static::templateName($template), $args, '', Paths::templatesPath());
}
/**
@@ -21,7 +21,7 @@
*/
public static function html(string $template, array $args = []): string
{
- return wc_get_template_html(static::templateName($template), $args, null, Paths::templatesPath());
+ return wc_get_template_html(static::templateName($template), $args, '', Paths::templatesPath());
}
private static function templateName(string $template): string
--- a/woocommerce-mercadopago/src/IO/Downloader.php
+++ b/woocommerce-mercadopago/src/IO/Downloader.php
@@ -167,9 +167,12 @@
{
$this->currentUser->validateUserNeededPermissions();
+ if (basename($filename) !== $filename) {
+ return false;
+ }
+
return $this->hasAllowedExtension($filename) &&
- $this->hasNoDisallowedCharacters($filename) &&
- $this->containsExpectedTerms($filename);
+ $this->isKnownLogFile($filename);
}
private function hasAllowedExtension(string $filename): bool
@@ -178,15 +181,13 @@
return (bool)preg_match($allowed_pattern, $filename);
}
- private function hasNoDisallowedCharacters(string $filename): bool
- {
- $disallowed = array('..', '/', '\', '.php', '.ini', '.exe', '.bat', '.sh', '.js', '.py', '.pl', '.sql', '.mdb', '.sqlite', '.zip', '.tar', '.gz', '.htaccess');
- return empty(array_intersect($disallowed, array($filename)));
- }
-
- private function containsExpectedTerms(string $filename): bool
+ private function isKnownLogFile(string $filename): bool
{
- $allowed_pattern = '/mercadopago|MercadoPago|fatal-errors/';
- return (bool)preg_match($allowed_pattern, $filename);
+ foreach ($this->pluginLogs as $logFile) {
+ if ($logFile->fileFullName === $filename) {
+ return true;
+ }
+ }
+ return false;
}
}
--- a/woocommerce-mercadopago/src/Transactions/AbstractPaymentTransaction.php
+++ b/woocommerce-mercadopago/src/Transactions/AbstractPaymentTransaction.php
@@ -46,12 +46,16 @@
$this->transaction->session_id = $this->checkout['session_id'];
}
+ $apiRoute = $this->transaction->getUris()['post'] ?? 'unknown';
+
try {
$data = $this->transaction->save();
$this->mercadopago->logs->file->info('Payment created', $this->gateway::LOG_SOURCE, $data);
+ $this->sendPaymentCreateResultMetric($apiRoute, null, $data);
return $data;
} catch (Exception $e) {
- $this->sendApiErrorMetric($this->transaction->getUris()['post'] ?? 'unknown', $e);
+ $this->sendApiErrorMetric($apiRoute, $e);
+ $this->sendPaymentCreateResultMetric($apiRoute, $e);
throw $e;
}
}
--- a/woocommerce-mercadopago/src/Transactions/AbstractTransaction.php
+++ b/woocommerce-mercadopago/src/Transactions/AbstractTransaction.php
@@ -5,6 +5,7 @@
use Exception;
use MercadoPagoPPSdkEntityPaymentPayment;
use MercadoPagoPPSdkEntityPreferencePreference;
+use MercadoPagoPPSdkExceptionsApiException;
use MercadoPagoPPSdkSdk;
use MercadoPagoWoocommerceGatewaysAbstractGateway;
use MercadoPagoWoocommerceLibrariesMetricsDatadog;
@@ -472,13 +473,54 @@
// Datadog value reflects $e->getCode(), which may be 0 when the SDK cannot attribute the failure to an HTTP status.
protected function sendApiErrorMetric(string $apiRoute, Exception $e): void
{
- $details = MetricContext::buildApiErrorDetails($apiRoute, $this->mercadopago ?? null);
+ $details = MetricContext::buildBaseMetricDetails($apiRoute, $this->mercadopago ?? null);
$details['sdk_instance_id'] = $this->resolveMetadataField('flow_id');
// payment_method carries checkout_type — the product bucket (super_token, credit_card, pix…), not the card brand. Intentional: PSW-3760 needs the SuperToken flow identifiable in API errors.
$paymentMethod = $this->resolveMetadataField('checkout_type');
Datadog::getInstance()->sendEvent('mp_api_error', (string) $e->getCode(), $e->getMessage(), $paymentMethod, $details);
}
+ // Records every payment-creation outcome (success and error) so it can be cross-referenced with the Core P&P funnel.
+ // The HTTP status class is inferred from control flow: the SDK only returns data on 2xx (handleResponse throws on
+ // non-2xx), so a returned call is a success. On an ApiException the class comes from the status it carries
+ // (getApiStatus), which keeps 5xx correct even if the SDK later raises ApiException for it; any other Exception is
+ // the SDK's generic "Internal API Error", i.e. a 5xx. A rejected card is NOT an API error — it is a 2xx whose
+ // business outcome lives in the response body, so on success payment_status carries that outcome
+ // (approved/rejected/pending/in_process/…). This runs on the successful payment return path, so it must never
+ // affect the flow: any failure here is swallowed silently (no block, no log) — a missing metric must never cost a payment.
+ protected function sendPaymentCreateResultMetric(string $apiRoute, ?Exception $e = null, ?array $data = null): void
+ {
+ try {
+ if ($e === null) {
+ $statusClass = '2xx';
+ $alertType = 'success';
+ $paymentStatus = is_array($data) ? ($data['status'] ?? null) : null;
+ $message = 'success';
+ } elseif ($e instanceof ApiException) {
+ $apiStatus = $e->getApiStatus();
+ $statusClass = ($apiStatus !== null && $apiStatus >= 500) ? '5xx' : '4xx';
+ $alertType = 'error';
+ $paymentStatus = null;
+ $message = $e->getMessage();
+ } else {
+ $statusClass = '5xx';
+ $alertType = 'error';
+ $paymentStatus = null;
+ $message = $e->getMessage();
+ }
+
+ $details = MetricContext::buildBaseMetricDetails($apiRoute, $this->mercadopago ?? null);
+ $details['sdk_instance_id'] = $this->resolveMetadataField('flow_id');
+ $details['alert_type'] = $alertType;
+ $details['payment_status'] = $paymentStatus;
+
+ $paymentMethod = $this->resolveMetadataField('checkout_type');
+ Datadog::getInstance()->sendEvent('mp_payment_create_result', $statusClass, $message, $paymentMethod, $details);
+ } catch (Throwable $t) {
+ // Intentionally ignored: observability must never block or pollute the payment flow.
+ }
+ }
+
// Assumes setCommonTransaction() has already run (called in every subtype constructor before save()).
// If a failure occurs before that point, the field will be absent and the value degrades to null — by design.
private function resolveMetadataField(string $field): ?string
--- a/woocommerce-mercadopago/src/Transactions/SupertokenTransaction.php
+++ b/woocommerce-mercadopago/src/Transactions/SupertokenTransaction.php
@@ -63,12 +63,16 @@
{
$this->updateTransactionItems();
+ $apiRoute = $this->transaction->getUris()['post'] ?? 'unknown';
+
try {
$data = $this->transaction->saveWithSuperToken($this->superToken, $this->paymentTypeId);
$this->mercadopago->logs->file->info('Payment created', $this->gateway::LOG_SOURCE, $data);
+ $this->sendPaymentCreateResultMetric($apiRoute, null, $data);
return $data;
} catch (Exception $e) {
- $this->sendApiErrorMetric($this->transaction->getUris()['post'] ?? 'unknown', $e);
+ $this->sendApiErrorMetric($apiRoute, $e);
+ $this->sendPaymentCreateResultMetric($apiRoute, $e);
throw $e;
}
}
--- a/woocommerce-mercadopago/src/WoocommerceMercadoPago.php
+++ b/woocommerce-mercadopago/src/WoocommerceMercadoPago.php
@@ -38,7 +38,7 @@
class WoocommerceMercadoPago
{
- private const PLUGIN_VERSION = '8.9.0';
+ private const PLUGIN_VERSION = '8.9.1';
private const PLUGIN_MIN_PHP = '7.4';
--- a/woocommerce-mercadopago/templates/admin/settings/settings.php
+++ b/woocommerce-mercadopago/templates/admin/settings/settings.php
@@ -634,6 +634,7 @@
const url = "<?php echo esc_url(admin_url('admin-ajax.php')); ?>";
const params = new URLSearchParams();
params.append('action', 'mp_download_log');
+ params.append('nonce', '<?php echo esc_js($downloadLogNonce); ?>');
selectedFiles.forEach((file) => {
params.append('files[]', file);
});
--- a/woocommerce-mercadopago/vendor/composer/autoload_static.php
+++ b/woocommerce-mercadopago/vendor/composer/autoload_static.php
@@ -7,7 +7,7 @@
class ComposerStaticInit18ea251a1d3302239f52e95d9f180dd5
{
public static $prefixLengthsPsr4 = array (
- 'M' =>
+ 'M' =>
array (
'MercadoPago\Woocommerce\' => 24,
'MercadoPago\PP\Sdk\' => 19,
@@ -15,11 +15,11 @@
);
public static $prefixDirsPsr4 = array (
- 'MercadoPago\Woocommerce\' =>
+ 'MercadoPago\Woocommerce\' =>
array (
0 => __DIR__ . '/../..' . '/src',
),
- 'MercadoPago\PP\Sdk\' =>
+ 'MercadoPago\PP\Sdk\' =>
array (
0 => __DIR__ . '/..' . '/mp-plugins/php-sdk/src',
),
--- a/woocommerce-mercadopago/woocommerce-mercadopago.php
+++ b/woocommerce-mercadopago/woocommerce-mercadopago.php
@@ -4,7 +4,7 @@
* Plugin Name: Mercado Pago
* Plugin URI: https://github.com/mercadopago/cart-woocommerce
* Description: Configure the payment options and accept payments with cards, ticket and money of Mercado Pago account.
- * Version: 8.9.0
+ * Version: 8.9.1
* Author: Mercado Pago
* Author URI: https://developers.mercadopago.com/
* Text Domain: woocommerce-mercadopago