Permalink
Browse files

New cart-modification-during-checkout prevention.

  • Loading branch information...
1 parent e72f21a commit b72d6e0b4cd3bde96a7a25e9727c152d757b68d8 @wrwrwr committed Apr 10, 2012
@@ -23,13 +23,6 @@
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
}
-// avoid hack attempts during the checkout procedure by checking the internal cartID
- if (isset($cart->cartID) && tep_session_is_registered('cartID')) {
- if ($cart->cartID != $cartID) {
- tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
- }
- }
-
// if no shipping method has been selected, redirect the customer to the shipping method selection page
if (!tep_session_is_registered('shipping')) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
@@ -28,13 +28,6 @@
tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
-// avoid hack attempts during the checkout procedure by checking the internal cartID
- if (isset($cart->cartID) && tep_session_is_registered('cartID')) {
- if ($cart->cartID != $cartID) {
- tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
- }
- }
-
// Stock Check
if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
$products = $cart->get_products();
@@ -32,13 +32,6 @@
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
-// avoid hack attempts during the checkout procedure by checking the internal cartID
- if (isset($cart->cartID) && tep_session_is_registered('cartID')) {
- if ($cart->cartID != $cartID) {
- tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
- }
- }
-
include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PROCESS);
// load selected payment module
@@ -44,11 +44,6 @@
require(DIR_WS_CLASSES . 'order.php');
$order = new order;
-// register a random ID in the session to check throughout the checkout procedure
-// against alterations in the shopping cart contents
- if (!tep_session_is_registered('cartID')) tep_session_register('cartID');
- $cartID = $cart->cartID;
-
// if the order contains only virtual products, forward the customer to the billing page as
// a shipping address is not needed
if ($order->content_type == 'virtual') {
@@ -11,7 +11,7 @@
*/
class shoppingCart {
- var $contents, $total, $weight, $cartID, $content_type;
+ var $contents, $total, $weight, $content_type;
function shoppingCart() {
$this->reset();
@@ -42,7 +42,7 @@ function restore_contents() {
}
}
-// reset per-session cart contents, but not the database contents
+// reset per-session cart contents, but not the database contents (this also resets the checkout)
$this->reset(false);
$products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
@@ -56,14 +56,12 @@ function restore_contents() {
}
$this->cleanup();
-
-// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
- $this->cartID = $this->generate_cart_id();
}
function reset($reset_database = false) {
global $customer_id;
+ $this->reset_checkout();
$this->contents = array();
$this->total = 0;
$this->weight = 0;
@@ -73,9 +71,15 @@ function reset($reset_database = false) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
}
+ }
- unset($this->cartID);
- if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
+// resets checkout data, should be used after any cart modification to prevent wrong shipping / payment costs
+ function reset_checkout() {
+ global $shipping, $payment;
+ $shipping = null;
+ $payment = null;
+ if (tep_session_is_registered('shipping')) tep_session_unregister('shipping');
+ if (tep_session_is_registered('payment')) tep_session_unregister('payment');
}
function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
@@ -121,6 +125,7 @@ function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
if ($this->in_cart($products_id_string)) {
$this->update_quantity($products_id_string, $qty, $attributes);
} else {
+ $this->reset_checkout();
$this->contents[$products_id_string] = array('qty' => (int)$qty);
// insert into database
if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')");
@@ -136,9 +141,6 @@ function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
}
$this->cleanup();
-
-// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
- $this->cartID = $this->generate_cart_id();
}
}
}
@@ -166,6 +168,7 @@ function update_quantity($products_id, $quantity = '', $attributes = '') {
}
if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity) && ($attributes_pass_check == true)) {
+ $this->reset_checkout();
$this->contents[$products_id_string] = array('qty' => (int)$quantity);
// update database
if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");
@@ -228,15 +231,13 @@ function in_cart($products_id) {
function remove($products_id) {
global $customer_id;
+ $this->reset_checkout();
unset($this->contents[$products_id]);
// remove from database
if (tep_session_is_registered('customer_id')) {
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
}
-
-// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
- $this->cartID = $this->generate_cart_id();
}
function remove_all() {

0 comments on commit b72d6e0

Please sign in to comment.