CVE-2023-6566 (PHP, published 2023-12-07T00:15Z)
Description: value: Business Logic Errors in GitHub repository microweber/microweber prior to 2.0.
Severity: nan (CVSS v3 base score: 6.5)
Weakness: NVD-CWE-Other \u2014 Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Repository: https://github.com/microweber/microweber
Files changed:
src/MicroweberPackages/Cart/CartManager.php
src/MicroweberPackages/Checkout/CheckoutManager.php
src/MicroweberPackages/Shop/tests/CheckoutTest.php
Commit message: update


Vulnerable code:
        $table =  'cart';
        $table =  'cart';
            $table =  'cart';
        $cart_table =  'cart';
                        if(isset($data[$cf['name_key']])){
                   } elseif (isset($cf['type']) and $cf['type'] == 'price' and isset($cf['name']) and isset($cf['value'])) {
            $table =  'cart';
                $table =  'cart';
        return  'cart';

Fixed code:
        $table = 'cart';



                        if (isset($params['for_checkout']) and $params['for_checkout']) {
                            // check if content is unpublished or deleted
                            $checkContent = get_content_by_id($item['rel_id']);
                            $removeFromCart = false;
                            if ($checkContent == false) {
                                $removeFromCart = true;
                            }

                            if ($checkContent and isset($checkContent['is_deleted']) and $checkContent['is_deleted'] == 1) {
                                $removeFromCart = true;
                            }
                            if ($checkContent and isset($checkContent['is_active']) and $checkContent['is_active'] == 0) {
                                $removeFromCart = true;
                            }

                            if ($removeFromCart) {
                                $this->remove_item($item['id']);
                                unset($get[$k]);
                                continue;
                            }
                        }


        $table = 'cart';
            $table = 'cart';
        $cart_table = 'cart';
                        if (isset($data[$cf['name_key']])) {
                    } elseif (isset($cf['type']) and $cf['type'] == 'price' and isset($cf['name']) and isset($cf['value'])) {
            $table = 'cart';
                $table = 'cart';
        return 'cart';
        $cart['for_checkout'] = true;



    public function testCheckoutDeletedProduct()
    {
        mw()->database_manager->extended_save_set_permission(true);

        $productPrice = rand(1, 9999);
        $title = 'test testCheckoutDeletedProduct prod ' . $productPrice;
        $params = array(
            'title' => $title,
            'content_type' => 'product',
            'subtype' => 'product',
            'custom_fields_advanced' => array(
                array('type' => 'dropdown', 'name' => 'Color', 'value' => array('Purple', 'Blue')),
                array('type' => 'price', 'name' => 'Price', 'value' => '9.99'),

            ),
            'data_fields_qty' => 10,
            'is_deleted' => 1,
            'is_active' => 1,);


        $saved_id = save_content($params);
        $get = get_content_by_id($saved_id);


        $add_to_cart = array(
            'content_id' => $saved_id,
            'price' => $productPrice,
        );
        $cart_add = update_cart($add_to_cart);


        $checkoutDetails = array();
        $checkoutDetails['email'] = 'client@microweber.com';
        $checkoutDetails['is_paid'] = 1;
        $checkoutDetails['order_completed'] = 1;


        $checkoutStatus = app()->order_manager->place_order($checkoutDetails);
        $content_data_after_order = content_data($saved_id);
        $this->assertEquals(10, $content_data_after_order['qty']);

        $productQuery = \MicroweberPackages\Product\Models\Product::query();
        $productQuery = $productQuery->whereHas('orders');
        $products = $productQuery->get();
        $this->assertTrue($products->isEmpty());

        $order = get_order_by_id($checkoutStatus);
        $this->assertNotNull($order);
        $this->assertNull($order['amount']);

    }




    public function testCheckoutUnpublishedProduct()
    {
        mw()->database_manager->extended_save_set_permission(true);

        $productPrice = rand(1, 9999);
        $title = 'test testCheckoutUnpublishedProduct prod ' . $productPrice;
        $params = array(
            'title' => $title,
            'content_type' => 'product',
            'subtype' => 'product',
            'custom_fields_advanced' => array(
                array('type' => 'dropdown', 'name' => 'Color', 'value' => array('Purple', 'Blue')),
                array('type' => 'price', 'name' => 'Price', 'value' => '9.99'),

            ),
            'data_fields_qty' => 11,
            'is_deleted' => 0,
            'is_active' => 0
        );


        $saved_id = save_content($params);
        $get = get_content_by_id($saved_id);


        $add_to_cart = array(
            'content_id' => $saved_id,
            'price' => $productPrice,
        );
        $cart_add = update_cart($add_to_cart);


        $checkoutDetails = array();
        $checkoutDetails['email'] = 'client@microweber.com';
        $checkoutDetails['is_paid'] = 1;
        $checkoutDetails['order_completed'] = 1;


        $checkoutStatus = app()->order_manager->place_order($checkoutDetails);
        $content_data_after_order = content_data($saved_id);
        $this->assertEquals(11, $content_data_after_order['qty']);

        $productQuery = \MicroweberPackages\Product\Models\Product::query();
        $productQuery = $productQuery->whereHas('orders');
        $products = $productQuery->get();
        $this->assertTrue($products->isEmpty());

        $order = get_order_by_id($checkoutStatus);
        $this->assertNotNull($order);
        $this->assertNull($order['amount']);

    }