Skip to content

Commit 334ce01

Browse files
Merge pull request #6009 from magento-borg/2.3.6-bugfixes-08112020
Resolved Issues: - MC-35002: Updated jQuery File Upload plugin - MC-36200: [Backport for 2.3.6] Protect payment related web APIs by CAPTCHA
2 parents 1335c7d + be23f15 commit 334ce01

File tree

87 files changed

+10903
-2951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+10903
-2951
lines changed

app/code/Magento/Authorization/Model/CompositeUserContext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ protected function add(UserContextInterface $userContext)
5656
}
5757

5858
/**
59-
* {@inheritdoc}
59+
* @inheritDoc
6060
*/
6161
public function getUserId()
6262
{
6363
return $this->getUserContext() ? $this->getUserContext()->getUserId() : null;
6464
}
6565

6666
/**
67-
* {@inheritdoc}
67+
* @inheritDoc
6868
*/
6969
public function getUserType()
7070
{
@@ -78,7 +78,7 @@ public function getUserType()
7878
*/
7979
protected function getUserContext()
8080
{
81-
if ($this->chosenUserContext === null) {
81+
if (!$this->chosenUserContext) {
8282
/** @var UserContextInterface $userContext */
8383
foreach ($this->userContexts as $userContext) {
8484
if ($userContext->getUserType() && $userContext->getUserId() !== null) {

app/code/Magento/Backend/view/adminhtml/web/js/media-uploader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ define([
3737
progressTmpl = mageTemplate('[data-template="uploader"]'),
3838
isResizeEnabled = this.options.isResizeEnabled,
3939
resizeConfiguration = {
40-
action: 'resize',
40+
action: 'resizeImage',
4141
maxWidth: this.options.maxWidth,
4242
maxHeight: this.options.maxHeight
4343
};
4444

4545
if (!isResizeEnabled) {
4646
resizeConfiguration = {
47-
action: 'resize'
47+
action: 'resizeImage'
4848
};
4949
}
5050

@@ -131,13 +131,13 @@ define([
131131
});
132132

133133
this.element.find('input[type=file]').fileupload('option', {
134-
process: [{
135-
action: 'load',
134+
processQueue: [{
135+
action: 'loadImage',
136136
fileTypes: /^image\/(gif|jpeg|png)$/
137137
},
138138
resizeConfiguration,
139139
{
140-
action: 'save'
140+
action: 'saveImage'
141141
}]
142142
});
143143
}

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\Captcha\Model;
99

10+
use Magento\Authorization\Model\UserContextInterface;
1011
use Magento\Captcha\Helper\Data;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\Math\Random;
1214

1315
/**
@@ -93,27 +95,35 @@ class DefaultModel extends \Zend\Captcha\Image implements \Magento\Captcha\Model
9395
*/
9496
private $randomMath;
9597

98+
/**
99+
* @var UserContextInterface
100+
*/
101+
private $userContext;
102+
96103
/**
97104
* @param \Magento\Framework\Session\SessionManagerInterface $session
98105
* @param \Magento\Captcha\Helper\Data $captchaData
99106
* @param ResourceModel\LogFactory $resLogFactory
100107
* @param string $formId
101-
* @param Random $randomMath
108+
* @param Random|null $randomMath
109+
* @param UserContextInterface|null $userContext
102110
* @throws \Zend\Captcha\Exception\ExtensionNotLoadedException
103111
*/
104112
public function __construct(
105113
\Magento\Framework\Session\SessionManagerInterface $session,
106114
\Magento\Captcha\Helper\Data $captchaData,
107115
\Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
108116
$formId,
109-
Random $randomMath = null
117+
Random $randomMath = null,
118+
?UserContextInterface $userContext = null
110119
) {
111120
parent::__construct();
112121
$this->session = $session;
113122
$this->captchaData = $captchaData;
114123
$this->resLogFactory = $resLogFactory;
115124
$this->formId = $formId;
116-
$this->randomMath = $randomMath ?? \Magento\Framework\App\ObjectManager::getInstance()->get(Random::class);
125+
$this->randomMath = $randomMath ?? ObjectManager::getInstance()->get(Random::class);
126+
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
117127
}
118128

119129
/**
@@ -152,6 +162,7 @@ public function isRequired($login = null)
152162
$this->formId,
153163
$this->getTargetForms()
154164
)
165+
|| $this->userContext->getUserType() === UserContextInterface::USER_TYPE_INTEGRATION
155166
) {
156167
return false;
157168
}
@@ -241,7 +252,7 @@ private function isOverLimitLoginAttempts($login)
241252
*/
242253
private function isUserAuth()
243254
{
244-
return $this->session->isLoggedIn();
255+
return $this->session->isLoggedIn() || $this->userContext->getUserId();
245256
}
246257

247258
/**
@@ -427,7 +438,7 @@ public function getWordLen()
427438
$to = self::DEFAULT_WORD_LENGTH_TO;
428439
}
429440

430-
return \Magento\Framework\Math\Random::getRandomNumber($from, $to);
441+
return Random::getRandomNumber($from, $to);
431442
}
432443

433444
/**
@@ -544,7 +555,7 @@ private function clearWord()
544555
*/
545556
protected function randomSize()
546557
{
547-
return \Magento\Framework\Math\Random::getRandomNumber(280, 300) / 100;
558+
return Random::getRandomNumber(280, 300) / 100;
548559
}
549560

550561
/**

app/code/Magento/Captcha/Observer/CaptchaStringResolver.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Captcha\Observer;
710

811
use Magento\Framework\App\RequestInterface;
912
use Magento\Framework\App\Request\Http as HttpRequest;
13+
use Magento\Captcha\Helper\Data as CaptchaHelper;
1014

1115
/**
1216
* Extract given captcha word.
@@ -22,12 +26,13 @@ class CaptchaStringResolver
2226
*/
2327
public function resolve(RequestInterface $request, $formId)
2428
{
25-
$captchaParams = $request->getPost(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE);
29+
$value = '';
30+
$captchaParams = $request->getPost(CaptchaHelper::INPUT_NAME_FIELD_VALUE);
2631
if (!empty($captchaParams) && !empty($captchaParams[$formId])) {
2732
$value = $captchaParams[$formId];
28-
} else {
29-
//For Web APIs
30-
$value = $request->getHeader('X-Captcha');
33+
} elseif ($headerValue = $request->getHeader('X-Captcha')) {
34+
//CAPTCHA was provided via header for this XHR/web API request.
35+
$value = $headerValue;
3136
}
3237

3338
return $value;

0 commit comments

Comments
 (0)