Merge pull request #19296 from woocommerce/fix/hash-function

Hash may not exist
This commit is contained in:
Claudiu Lodromanean 2018-03-12 10:58:31 -07:00 committed by GitHub
commit 0cc1b78341
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -54,7 +54,10 @@ class WC_Download_Handler {
$order = wc_get_order( $order_id );
$email_address = is_a( $order, 'WC_Order' ) ? $order->get_billing_email() : null;
if ( is_null( $email_address ) || ! hash_equals( $_GET['uid'], hash( 'sha256', $email_address ) ) ) {
// Prepare email address hash.
$email_hash = function_exists( 'hash' ) ? hash( 'sha256', $email_address ) : sha1( $email_address );
if ( is_null( $email_address ) || ! hash_equals( $_GET['uid'], $email_hash ) ) {
self::download_error( __( 'Invalid download link.', 'woocommerce' ) );
}
}

View File

@ -368,6 +368,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
$product = $this->get_product();
$order = $this->get_order();
$product_id = $this->get_variation_id() ? $this->get_variation_id() : $this->get_product_id();
$email_hash = function_exists( 'hash' ) ? hash( 'sha256', $order->get_billing_email() ) : sha1( $order->get_billing_email() );
if ( $product && $order && $product->is_downloadable() && $order->is_download_permitted() ) {
$data_store = WC_Data_Store::load( 'customer-download' );
@ -387,7 +388,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
$files[ $download_id ]['download_url'] = add_query_arg( array(
'download_file' => $product_id,
'order' => $order->get_order_key(),
'uid' => hash( 'sha256', $order->get_billing_email() ),
'uid' => $email_hash,
'key' => $download_id,
), trailingslashit( home_url() ) );
}