Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Processor/CheckoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public function run(CheckoutData $data)
throw CouldNotProcessCheckout::failedToFindCart($data->getCartId());
}

$cartTotal = (int) round($cart->getOrderTotal(true) * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API);

if (!$data->getCreateAfterAuthorization()) {
$this->processCreateOrder($cart, $data->getPaymentMethod());
}
Expand All @@ -109,7 +111,8 @@ public function run(CheckoutData $data)
$data->getSelectedCard(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

The selectedCard parameter, which originates from user-supplied data in the CheckoutData object, is passed to the payment initialization service on line 111. This ID is used to retrieve a saved card alias from the database without any ownership verification in the downstream SaferPayCardAliasRepository::getSavedCardAliasFromId method. An attacker could potentially use another user's saved card by providing the corresponding id_saferpay_card_alias in their request.

To remediate this, verify that the selectedCard ID belongs to the currently authenticated customer before using it. You can use the SaferPayCardAliasRepository::getCustomerIdByReferenceId method for this purpose.

$data->getFieldToken(),
$data->getSuccessController(),
$data->getIsWebhook()
$data->getIsWebhook(),
$cartTotal
);
} catch (\Exception $exception) {
throw new SaferPayApiException('Failed to initialize payment API', SaferPayApiException::INITIALIZE);
Expand Down Expand Up @@ -196,15 +199,17 @@ private function processInitializePayment(
$selectedCard,
$fieldToken,
$successController,
$isWebhook
$isWebhook,
$cartTotal = null
) {
$request = $this->saferPayInitialize->buildRequest(
$paymentMethod,
$isBusinessLicense,
$selectedCard,
$fieldToken,
$successController,
$isWebhook
$isWebhook,
$cartTotal
);

return $this->saferPayInitialize->initialize($request, $isBusinessLicense);
Expand Down
11 changes: 7 additions & 4 deletions src/Service/Request/InitializeRequestObjectCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ public function create(
$customerId,
$isBusinessLicence,
$alias = null,
$fieldToken = null
$fieldToken = null,
$cartTotal = null
) {
$requestHeader = $this->requestObjectCreator->createRequestHeader();
$terminalId = Configuration::get(SaferPayConfig::TERMINAL_ID . SaferPayConfig::getConfigSuffix());

$cartDetails = $cart->getSummaryDetails();
$totalPrice = $cartDetails['total_price'] * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API;
$totalPrice = (int) (round($totalPrice));
$totalPrice = $cartTotal;
if ($cartTotal === null) {
$cartDetails = $cart->getSummaryDetails();
$totalPrice = (int) round($cartDetails['total_price'] * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API);
}
Comment on lines +66 to +70

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and to avoid assigning a value to $totalPrice that might be immediately overwritten, you can restructure this conditional logic.

        if ($cartTotal !== null) {
            $totalPrice = $cartTotal;
        } else {
            $cartDetails = $cart->getSummaryDetails();
            $totalPrice = (int) round($cartDetails['total_price'] * SaferPayConfig::AMOUNT_MULTIPLIER_FOR_API);
        }

$payment = $this->requestObjectCreator->createPayment($cart, $totalPrice);
$payer = new Payer();

Expand Down
6 changes: 4 additions & 2 deletions src/Service/SaferPayInitialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function buildRequest(
$selectedCard = -1,
$fieldToken = null,
$successController = null,
$isWebhook = 1
$isWebhook = 1,
$cartTotal = null
) {
$customerEmail = $this->context->customer->email;
$cartId = $this->context->cart->id;
Expand Down Expand Up @@ -155,7 +156,8 @@ public function buildRequest(
$this->context->cart->id_customer,
$isBusinessLicence,
$alias,
$fieldToken
$fieldToken,
$cartTotal
);

return $initializeRequest;
Expand Down
Loading