Timing attack woocommerce, simplify commerce gateway
The WooCommerce Simplify Commerce gateway compares the MD5 payment signature with a plain string comparison, which is not constant-time. An attacker could in principle recover the correct signature character by character through repeated requests and timing differences, then mark orders as paid.
b258ea62bf297b02afa9854 Follow
Originally disclosed on HackerOne
- Fixed in 38 days
- Paid in 38 days
- Disclosed after 3 months
file class-wc-gateway-simplify-commerce.php method return_handler e.g. where woocommerce marks the order regarding its payment / transaction.
public function return_handler() {
@ob_clean();
header( 'HTTP/1.1 200 OK' );
if ( isset( $_REQUEST['reference'] ) && isset( $_REQUEST['paymentId'] ) && isset( $_REQUEST['signature'] ) ) {
$signature = strtoupper( md5( $_REQUEST['amount'] . $_REQUEST['reference'] . $_REQUEST['paymentId'] . $_REQUEST['paymentDate'] . $_REQUEST['paymentStatus'] . $this->private_key ) );
$order_id = absint( $_REQUEST['reference'] );
$order = wc_get_order( $order_id );
if ( $signature === $_REQUEST['signature'] ) {
$order_complete = $this->process_order_status( $order, $_REQUEST['paymentId'], $_REQUEST['paymentStatus'], $_REQUEST['paymentDate'] );
if ( ! $order_complete ) {
$order->update_status( 'failed', __( 'Payment was declined by Simplify Commerce.', 'woocommerce' ) );
}
wp_redirect( $this->get_return_url( $order ) );
exit();
}
}
wp_redirect( wc_get_page_permalink( 'cart' ) );
exit();
}
Here is used md5 for signature generation, but string comparison isn't safe towards timing attack. Having in mind the length of the md5 hash string 32 and minimal character set used for it a-z and 0-9, then discovering the right signature will require 32 rounds * X requests per character => no need even for distributed attack regarding successful guessing the generated signature.
In order to protect the customers and merchants I would like to point the usage of hash_equals with its wordpress alternative e.g.
... if (hash_equals($signature, $_REQUEST['signature'])) ...
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the signature is compared using PHP's normal string equality operator, which short-circuits on the first mismatched byte and therefore leaks timing information.
Impact
An attacker could potentially recover the valid signature and have orders marked as paid without a real payment, though the text only argues this is feasible rather than demonstrating it.
What the attacker needed
Network access to the return handler; ability to send many requests
The fix
The comparison should be replaced with a constant-time comparison such as hash_equals, which the text recommends.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program checks a password or signature, it often stops comparing as soon as it finds a wrong character. That means a wrong guess that matches more characters takes slightly longer to reject. By measuring those tiny time differences over many requests, an attacker can guess the secret one character at a time instead of all at once.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.