Skip to content

Commit 88400b0

Browse files
author
Yevhen Bohaienko
committed
Merge branch '2.2.8-develop' into MAGETWO-97043
2 parents b0c8c44 + 8dcc1b4 commit 88400b0

File tree

20 files changed

+292
-518
lines changed

20 files changed

+292
-518
lines changed

.htaccess

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@
364364
Require all denied
365365
</IfVersion>
366366
</Files>
367+
<Files .user.ini>
368+
<IfVersion < 2.4>
369+
order allow,deny
370+
deny from all
371+
</IfVersion>
372+
<IfVersion >= 2.4>
373+
Require all denied
374+
</IfVersion>
375+
</Files>
367376

368377
# For 404s and 403s that aren't handled by the application, show plain 404 response
369378
ErrorDocument 404 /pub/errors/404.php

.htaccess.sample

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,15 @@
341341
Require all denied
342342
</IfVersion>
343343
</Files>
344+
<Files .user.ini>
345+
<IfVersion < 2.4>
346+
order allow,deny
347+
deny from all
348+
</IfVersion>
349+
<IfVersion >= 2.4>
350+
Require all denied
351+
</IfVersion>
352+
</Files>
344353

345354
# For 404s and 403s that aren't handled by the application, show plain 404 response
346355
ErrorDocument 404 /pub/errors/404.php

app/code/Magento/AdminNotification/Block/Grid/Renderer/Actions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Magento\AdminNotification\Block\Grid\Renderer;
1010

11+
/**
12+
* Renderer class for action in the admin notifications grid.
13+
*/
1114
class Actions extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1215
{
1316
/**

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFolder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Exception\NotFoundException;
1011

1112
/**
1213
* Delete image folder.
@@ -57,6 +58,10 @@ public function __construct(
5758
*/
5859
public function execute()
5960
{
61+
if (!$this->getRequest()->isPost()) {
62+
throw new NotFoundException(__('Page not found'));
63+
}
64+
6065
try {
6166
$path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
6267
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/NewFolder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Exception\NotFoundException;
1011

1112
/**
1213
* Creates new folder.
@@ -50,6 +51,10 @@ public function __construct(
5051
*/
5152
public function execute()
5253
{
54+
if (!$this->getRequest()->isPost()) {
55+
throw new NotFoundException(__('Page not found'));
56+
}
57+
5358
try {
5459
$this->_initAction();
5560
$name = $this->getRequest()->getPost('name');

app/code/Magento/Wishlist/Block/Customer/Sharing.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
namespace Magento\Wishlist\Block\Customer;
1313

14+
use Magento\Captcha\Block\Captcha;
15+
1416
/**
1517
* @api
1618
* @since 100.0.2
@@ -60,6 +62,20 @@ public function __construct(
6062
*/
6163
protected function _prepareLayout()
6264
{
65+
if (!$this->getChildBlock('captcha')) {
66+
$this->addChild(
67+
'captcha',
68+
Captcha::class,
69+
[
70+
'cacheable' => false,
71+
'after' => '-',
72+
'form_id' => 'share_wishlist_form',
73+
'image_width' => 230,
74+
'image_height' => 230
75+
]
76+
);
77+
}
78+
6379
$this->pageConfig->getTitle()->set(__('Wish List Sharing'));
6480
}
6581

app/code/Magento/Wishlist/Controller/Index/Send.php

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
use Magento\Framework\App\Action;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\ResponseInterface;
1112
use Magento\Framework\Exception\NotFoundException;
1213
use Magento\Framework\Session\Generic as WishlistSession;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Framework\Controller\ResultFactory;
1516
use Magento\Framework\View\Result\Layout as ResultLayout;
17+
use Magento\Captcha\Helper\Data as CaptchaHelper;
18+
use Magento\Captcha\Observer\CaptchaStringResolver;
19+
use Magento\Framework\Controller\Result\Redirect;
20+
use Magento\Framework\Controller\ResultInterface;
21+
use Magento\Framework\App\ObjectManager;
22+
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
23+
use Magento\Framework\Exception\LocalizedException;
24+
use Magento\Customer\Model\Customer;
1625

1726
/**
1827
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -69,6 +78,16 @@ class Send extends \Magento\Wishlist\Controller\AbstractIndex
6978
*/
7079
protected $storeManager;
7180

81+
/**
82+
* @var CaptchaHelper
83+
*/
84+
private $captchaHelper;
85+
86+
/**
87+
* @var CaptchaStringResolver
88+
*/
89+
private $captchaStringResolver;
90+
7291
/**
7392
* @param Action\Context $context
7493
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
@@ -81,6 +100,8 @@ class Send extends \Magento\Wishlist\Controller\AbstractIndex
81100
* @param WishlistSession $wishlistSession
82101
* @param ScopeConfigInterface $scopeConfig
83102
* @param StoreManagerInterface $storeManager
103+
* @param CaptchaHelper|null $captchaHelper
104+
* @param CaptchaStringResolver|null $captchaStringResolver
84105
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
85106
*/
86107
public function __construct(
@@ -94,7 +115,9 @@ public function __construct(
94115
\Magento\Customer\Helper\View $customerHelperView,
95116
WishlistSession $wishlistSession,
96117
ScopeConfigInterface $scopeConfig,
97-
StoreManagerInterface $storeManager
118+
StoreManagerInterface $storeManager,
119+
CaptchaHelper $captchaHelper = null,
120+
CaptchaStringResolver $captchaStringResolver = null
98121
) {
99122
$this->_formKeyValidator = $formKeyValidator;
100123
$this->_customerSession = $customerSession;
@@ -106,27 +129,45 @@ public function __construct(
106129
$this->wishlistSession = $wishlistSession;
107130
$this->scopeConfig = $scopeConfig;
108131
$this->storeManager = $storeManager;
132+
$this->captchaHelper = $captchaHelper ?: ObjectManager::getInstance()->get(CaptchaHelper::class);
133+
$this->captchaStringResolver = $captchaStringResolver ?
134+
: ObjectManager::getInstance()->get(CaptchaStringResolver::class);
135+
109136
parent::__construct($context);
110137
}
111138

112139
/**
113-
* Share wishlist
114-
*
115-
* @return \Magento\Framework\Controller\Result\Redirect
140+
* @return ResponseInterface|Redirect|ResultInterface
116141
* @throws NotFoundException
142+
* @throws LocalizedException
117143
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
118144
* @SuppressWarnings(PHPMD.NPathComplexity)
119145
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
146+
* @throws \Zend_Validate_Exception
120147
*/
121148
public function execute()
122149
{
123150
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
124151
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
152+
$captchaFormName = 'share_wishlist_form';
153+
/** @var CaptchaModel $captchaModel */
154+
$captchaModel = $this->captchaHelper->getCaptcha($captchaFormName);
155+
125156
if (!$this->_formKeyValidator->validate($this->getRequest())) {
126157
$resultRedirect->setPath('*/*/');
127158
return $resultRedirect;
128159
}
129160

161+
$isCorrectCaptcha = $this->validateCaptcha($captchaModel, $captchaFormName);
162+
163+
$this->logCaptchaAttempt($captchaModel);
164+
165+
if (!$isCorrectCaptcha) {
166+
$this->messageManager->addErrorMessage(__('Incorrect CAPTCHA'));
167+
$resultRedirect->setPath('*/*/share');
168+
return $resultRedirect;
169+
}
170+
130171
$wishlist = $this->wishlistProvider->getWishlist();
131172
if (!$wishlist) {
132173
throw new NotFoundException(__('Page not found.'));
@@ -288,4 +329,43 @@ protected function getWishlistItems(ResultLayout $resultLayout)
288329
->getBlock('wishlist.email.items')
289330
->toHtml();
290331
}
332+
333+
/**
334+
* Log customer action attempts
335+
* @param CaptchaModel $captchaModel
336+
* @return void
337+
*/
338+
private function logCaptchaAttempt(CaptchaModel $captchaModel)
339+
{
340+
/** @var Customer $customer */
341+
$customer = $this->_customerSession->getCustomer();
342+
$email = '';
343+
344+
if ($customer->getId()) {
345+
$email = $customer->getEmail();
346+
}
347+
348+
$captchaModel->logAttempt($email);
349+
}
350+
351+
/**
352+
* @param CaptchaModel $captchaModel
353+
* @param string $captchaFormName
354+
* @return bool
355+
*/
356+
private function validateCaptcha(CaptchaModel $captchaModel, string $captchaFormName) : bool
357+
{
358+
if ($captchaModel->isRequired()) {
359+
$word = $this->captchaStringResolver->resolve(
360+
$this->getRequest(),
361+
$captchaFormName
362+
);
363+
364+
if (!$captchaModel->isCorrect($word)) {
365+
return false;
366+
}
367+
}
368+
369+
return true;
370+
}
291371
}

0 commit comments

Comments
 (0)