Skip to content

Commit 64180fc

Browse files
committed
ACP2E-4049: Unknown IPNs from PayPal abuses application IPN processor
1 parent 76e2a92 commit 64180fc

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

app/code/Magento/Paypal/Controller/Ipn/Index.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22
/**
3-
*
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
65
*/
76
declare(strict_types=1);
87

@@ -13,6 +12,7 @@
1312
use Magento\Framework\App\Request\InvalidRequestException;
1413
use Magento\Framework\App\RequestInterface;
1514
use Magento\Framework\Exception\RemoteServiceUnavailableException;
15+
use Magento\Paypal\Model\Exception\UnknownIpnException;
1616
use Magento\Sales\Model\OrderFactory;
1717

1818
/**
@@ -86,19 +86,23 @@ public function execute()
8686
try {
8787
$data = $this->getRequest()->getPostValue();
8888
$this->_ipnFactory->create(['data' => $data])->processIpnRequest();
89-
$incrementId = $this->getRequest()->getPostValue()['invoice'];
90-
$this->_eventManager->dispatch(
91-
'paypal_checkout_success',
92-
[
93-
'order' => $this->orderFactory->create()->loadByIncrementId($incrementId)
94-
]
95-
);
89+
$incrementId = $data['invoice'] ?? null;
90+
if ($incrementId) {
91+
$this->_eventManager->dispatch(
92+
'paypal_checkout_success',
93+
[
94+
'order' => $this->orderFactory->create()->loadByIncrementId($incrementId)
95+
]
96+
);
97+
}
9698
} catch (RemoteServiceUnavailableException $e) {
9799
$this->_logger->critical($e);
98100
$this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse();
99101
/** @todo eliminate usage of exit statement */
100102
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
101103
exit;
104+
} catch (UnknownIpnException $e) {
105+
$this->_logger->critical($e);
102106
} catch (\Exception $e) {
103107
$this->_logger->critical($e);
104108
$this->getResponse()->setHttpResponseCode(500);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
namespace Magento\Paypal\Model\Exception;
7+
8+
use Magento\Framework\Exception\LocalizedException;
9+
10+
/**
11+
* Exception for unknown or invalid PayPal IPN requests
12+
*/
13+
class UnknownIpnException extends LocalizedException
14+
{
15+
}

app/code/Magento/Paypal/Model/Ipn.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Paypal\Model;
88

99
use Exception;
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Paypal\Model\Exception\UnknownIpnException;
1213
use Magento\Sales\Model\Order;
1314
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
1415
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
@@ -151,6 +152,11 @@ protected function _getConfig()
151152
protected function _getOrder()
152153
{
153154
$incrementId = $this->getRequestData('invoice');
155+
if (!$incrementId) {
156+
throw new UnknownIpnException(
157+
__('Missing invoice field in IPN request.')
158+
);
159+
}
154160
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
155161
if (!$this->_order->getId()) {
156162
// phpcs:ignore Magento2.Exceptions.DirectThrow

0 commit comments

Comments
 (0)