Skip to content

Commit b9b19ed

Browse files
committed
Merge remote-tracking branch 'origin/2.4.7-develop' into Sync-2.4.7-develop
2 parents 488c103 + c62e045 commit b9b19ed

File tree

58 files changed

+916
-177
lines changed

Some content is hidden

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

58 files changed

+916
-177
lines changed

app/code/Magento/AdminAnalytics/ViewModel/Metadata.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
namespace Magento\AdminAnalytics\ViewModel;
1010

1111
use Magento\Config\Model\Config\Backend\Admin\Custom;
12+
use Magento\Csp\Helper\CspNonceProvider;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\App\ObjectManager;
1315
use Magento\Framework\App\ProductMetadataInterface;
1416
use Magento\Backend\Model\Auth\Session;
1517
use Magento\Framework\App\State;
@@ -21,6 +23,11 @@
2123
*/
2224
class Metadata implements ArgumentInterface
2325
{
26+
/**
27+
* @var string
28+
*/
29+
private $nonce;
30+
2431
/**
2532
* @var State
2633
*/
@@ -41,22 +48,33 @@ class Metadata implements ArgumentInterface
4148
*/
4249
private $config;
4350

51+
/**
52+
* @var CspNonceProvider
53+
*/
54+
private $nonceProvider;
55+
4456
/**
4557
* @param ProductMetadataInterface $productMetadata
4658
* @param Session $authSession
4759
* @param State $appState
4860
* @param ScopeConfigInterface $config
61+
* @param CspNonceProvider|null $nonceProvider
4962
*/
5063
public function __construct(
5164
ProductMetadataInterface $productMetadata,
5265
Session $authSession,
5366
State $appState,
54-
ScopeConfigInterface $config
67+
ScopeConfigInterface $config,
68+
CspNonceProvider $nonceProvider = null
5569
) {
5670
$this->productMetadata = $productMetadata;
5771
$this->authSession = $authSession;
5872
$this->appState = $appState;
5973
$this->config = $config;
74+
75+
$this->nonceProvider = $nonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
76+
77+
$this->nonce = $this->nonceProvider->generateNonce();
6078
}
6179

6280
/**
@@ -156,4 +174,14 @@ public function getCurrentUserRoleName(): string
156174
{
157175
return $this->authSession->getUser()->getRole()->getRoleName();
158176
}
177+
178+
/**
179+
* Get a random nonce for each request.
180+
*
181+
* @return string
182+
*/
183+
public function getNonce(): string
184+
{
185+
return $this->nonce;
186+
}
159187
}

app/code/Magento/AdminAnalytics/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"magento/module-config": "*",
1212
"magento/module-store": "*",
1313
"magento/module-ui": "*",
14-
"magento/module-release-notification": "*"
14+
"magento/module-release-notification": "*",
15+
"magento/module-csp": "*"
1516
},
1617
"type": "magento2-module",
1718
"license": [

app/code/Magento/AdminAnalytics/view/adminhtml/templates/tracking.phtml

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

77
/**
88
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
9+
* @var \Magento\Framework\Escaper $escaper
910
*/
1011
?>
1112

@@ -22,18 +23,25 @@
2223
<?php
2324
/** @var \Magento\AdminAnalytics\ViewModel\Metadata $metadata */
2425
$metadata = $block->getMetadata();
26+
$nonce = $escaper->escapeJs($metadata->getNonce());
2527
$scriptString = '
2628
var adminAnalyticsMetadata = {
27-
"secure_base_url": "' . $block->escapeJs($metadata->getSecureBaseUrlForScope()) . '",
28-
"version": "' . $block->escapeJs($metadata->getMagentoVersion()) . '",
29-
"product_edition": "' . $block->escapeJs($metadata->getProductEdition()) . '",
30-
"user": "' . $block->escapeJs($metadata->getCurrentUser()) . '",
31-
"mode": "' . $block->escapeJs($metadata->getMode()) . '",
32-
"store_name_default": "' . $block->escapeJs($metadata->getStoreNameForScope()) . '",
33-
"admin_user_created": "' . $block->escapeJs($metadata->getCurrentUserCreatedDate()) . '",
34-
"admin_user_logdate": "' . $block->escapeJs($metadata->getCurrentUserLogDate()) . '",
35-
"admin_user_role_name": "' . $block->escapeJs($metadata->getCurrentUserRoleName()) . '"
29+
"secure_base_url": "' . $escaper->escapeJs($metadata->getSecureBaseUrlForScope()) . '",
30+
"version": "' . $escaper->escapeJs($metadata->getMagentoVersion()) . '",
31+
"product_edition": "' . $escaper->escapeJs($metadata->getProductEdition()) . '",
32+
"user": "' . $escaper->escapeJs($metadata->getCurrentUser()) . '",
33+
"mode": "' . $escaper->escapeJs($metadata->getMode()) . '",
34+
"store_name_default": "' . $escaper->escapeJs($metadata->getStoreNameForScope()) . '",
35+
"admin_user_created": "' . $escaper->escapeJs($metadata->getCurrentUserCreatedDate()) . '",
36+
"admin_user_logdate": "' . $escaper->escapeJs($metadata->getCurrentUserLogDate()) . '",
37+
"admin_user_role_name": "' . $escaper->escapeJs($metadata->getCurrentUserRoleName()) . '"
3638
};
39+
40+
var digitalData = {
41+
"nonce": "' . $nonce . '"
42+
};
43+
44+
var cspNonce = "' . $nonce . '";
3745
';
3846
?>
3947
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); ?>

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<tab id="general" translate="label" sortOrder="100">
1111
<label>General</label>
1212
</tab>
13+
<tab id="security" translate="label" sortOrder="200">
14+
<label>Security</label>
15+
</tab>
1316
<tab id="service" translate="label" sortOrder="99999">
1417
<label>Services</label>
1518
</tab>

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AddToCartFromStorefrontProductPageActionGroup.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<arguments>
1717
<argument name="productName"/>
1818
</arguments>
19-
2019
<waitForElementNotVisible selector="{{StorefrontProductActionSection.addToCartDisabled}}" stepKey="waitForAddToCartButtonToRemoveDisabledState"/>
2120
<waitForElementClickable selector="{{StorefrontProductActionSection.addToCart}}" stepKey="waitForAddToCartButton"/>
2221
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart"/>

app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyThatRecentlyOrderedWidgetShowOnlyFiveProductTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addSecondSimpleProductProductToCart6">
8787
<argument name="product" value="$$createProduct6$$"/>
8888
</actionGroup>
89-
89+
9090
<!--Place the order-->
9191
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="goToShoppingCartPage"/>
9292
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectPaymentMethod"/>

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected function setUp(): void
184184
$this->customOptionFactoryMock
185185
]
186186
];
187-
$this->prepareObjectManager($objects);
187+
$this->objectManager->prepareObjectManager($objects);
188188

189189
$this->helper = $this->objectManager->getObject(
190190
Helper::class,
@@ -772,22 +772,4 @@ private function assembleProductRepositoryMock($links)
772772
->method('getById')
773773
->willReturnMap($repositoryReturnMap);
774774
}
775-
776-
/**
777-
* @param $map
778-
*/
779-
private function prepareObjectManager($map)
780-
{
781-
$objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
782-
->addMethods(['getInstance'])
783-
->onlyMethods(['get'])
784-
->getMockForAbstractClass();
785-
786-
$objectManagerMock->method('getInstance')->willReturnSelf();
787-
$objectManagerMock->method('get')->willReturnMap($map);
788-
789-
$reflectionProperty = new \ReflectionProperty(\Magento\Framework\App\ObjectManager::class, '_instance');
790-
$reflectionProperty->setAccessible(true);
791-
$reflectionProperty->setValue($objectManagerMock);
792-
}
793775
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Observer;
9+
10+
use Magento\Csp\Model\Collector\DynamicCollector;
11+
use Magento\Csp\Model\Policy\FetchPolicy;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\Event\ObserverInterface;
14+
use Magento\Framework\Translate\InlineInterface;
15+
16+
/**
17+
* Observer for adding CSP policy for inline translation
18+
*/
19+
class CspPolicyObserver implements ObserverInterface
20+
{
21+
/**
22+
* @var InlineInterface
23+
*/
24+
private InlineInterface $inlineTranslate;
25+
26+
/**
27+
* @var DynamicCollector
28+
*/
29+
private DynamicCollector $dynamicCollector;
30+
31+
/**
32+
* @param InlineInterface $inlineTranslate
33+
* @param DynamicCollector $dynamicCollector
34+
*/
35+
public function __construct(InlineInterface $inlineTranslate, DynamicCollector $dynamicCollector)
36+
{
37+
$this->inlineTranslate = $inlineTranslate;
38+
$this->dynamicCollector = $dynamicCollector;
39+
}
40+
41+
/**
42+
* Override CSP policy for checkout page wit inline translation
43+
*
44+
* @param Observer $observer
45+
* @return void
46+
*
47+
* @throws \Exception
48+
*
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
50+
*/
51+
public function execute(Observer $observer): void
52+
{
53+
if ($this->inlineTranslate->isAllowed()) {
54+
$policy = new FetchPolicy(
55+
'script-src',
56+
false,
57+
[],
58+
[],
59+
true,
60+
true,
61+
false,
62+
[],
63+
[]
64+
);
65+
66+
$this->dynamicCollector->add($policy);
67+
}
68+
}
69+
}

app/code/Magento/Checkout/Test/Mftf/ActionGroup/GuestCheckoutFillingShippingSectionActionGroup.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<selectOption selector="{{CheckoutShippingSection.region}}" userInput="{{customerAddressVar.state}}" stepKey="selectRegion"/>
2929
<fillField selector="{{CheckoutShippingSection.postcode}}" userInput="{{customerAddressVar.postcode}}" stepKey="enterPostcode"/>
3030
<fillField selector="{{CheckoutShippingSection.telephone}}" userInput="{{customerAddressVar.telephone}}" stepKey="enterTelephone"/>
31-
<waitForPageLoad stepKey="waitForLoadingMask"/>
31+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
3232
<waitForElementClickable selector="{{CheckoutShippingMethodsSection.checkShippingMethodByName('shippingMethod')}}" stepKey="waitForShippingMethod"/>
3333
<click selector="{{CheckoutShippingMethodsSection.checkShippingMethodByName('shippingMethod')}}" stepKey="selectShippingMethod"/>
3434
<waitForPageLoad stepKey="waitForShippingLoading"/>

app/code/Magento/Checkout/Test/Mftf/Test/CheckoutSpecificDestinationsTest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
</actionGroup>
7777
<after>
7878
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
79-
8079
<deleteData createDataKey="simpleProduct" stepKey="deleteProduct"/>
8180
<deleteData createDataKey="defaultCategory" stepKey="deleteCategory"/>
8281
</after>

0 commit comments

Comments
 (0)