From b727f4ce649b1c921aa9dfae3fd9c2864324b0bb Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 7 Mar 2018 15:13:40 +0000 Subject: [PATCH] Hash may not exist --- includes/class-wc-download-handler.php | 5 ++++- includes/class-wc-order-item-product.php | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-download-handler.php b/includes/class-wc-download-handler.php index 03dbbb5012d..f36e48af984 100644 --- a/includes/class-wc-download-handler.php +++ b/includes/class-wc-download-handler.php @@ -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' ) ); } } diff --git a/includes/class-wc-order-item-product.php b/includes/class-wc-order-item-product.php index 362a7e73978..10953473569 100644 --- a/includes/class-wc-order-item-product.php +++ b/includes/class-wc-order-item-product.php @@ -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() ) ); }