Skip to content

Commit 863fb2e

Browse files
author
Oleksandr Gorkun
committed
MC-30981: CSP rules not enabled on first login to admin
1 parent 56009fc commit 863fb2e

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Csp\Model\Collector\CspWhitelistXml;
10+
11+
use Magento\Framework\Serialize\SerializerInterface;
12+
use Magento\Framework\Config\Data\Scoped;
13+
use Magento\Framework\Config\ScopeInterface;
14+
use Magento\Framework\Config\CacheInterface;
15+
16+
/**
17+
* Provides CSP whitelist configuration
18+
*/
19+
class Data extends Scoped
20+
{
21+
/**
22+
* Scope priority loading scheme
23+
*
24+
* @var array
25+
*/
26+
protected $_scopePriorityScheme = ['global'];
27+
28+
/**
29+
* Constructor
30+
*
31+
* @param Reader $reader
32+
* @param ScopeInterface $configScope
33+
* @param CacheInterface $cache
34+
* @param SerializerInterface $serializer
35+
*/
36+
public function __construct(
37+
Reader $reader,
38+
ScopeInterface $configScope,
39+
CacheInterface $cache,
40+
SerializerInterface $serializer
41+
) {
42+
parent::__construct($reader, $configScope, $cache, 'csp_whitelist_config', $serializer);
43+
}
44+
}

app/code/Magento/Csp/Model/Collector/CspWhitelistXmlCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Csp\Model\Collector;
1010

1111
use Magento\Csp\Api\PolicyCollectorInterface;
12-
use Magento\Csp\Model\Collector\CspWhitelistXml\Reader as ConfigReader;
12+
use Magento\Framework\Config\DataInterface as ConfigReader;
1313
use Magento\Csp\Model\Policy\FetchPolicy;
1414

1515
/**
@@ -36,7 +36,7 @@ public function __construct(ConfigReader $configReader)
3636
public function collect(array $defaultPolicies = []): array
3737
{
3838
$policies = $defaultPolicies;
39-
$config = $this->configReader->read();
39+
$config = $this->configReader->get(null);
4040
foreach ($config as $policyId => $values) {
4141
$policies[] = new FetchPolicy(
4242
$policyId,

app/code/Magento/Csp/etc/di.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
<argument name="fileName" xsi:type="string">csp_whitelist.xml</argument>
5050
</arguments>
5151
</type>
52+
<type name="Magento\Csp\Model\Collector\CspWhitelistXml\Data">
53+
<arguments>
54+
<argument name="reader" xsi:type="object">Magento\Csp\Model\Collector\CspWhitelistXml\Reader\Proxy</argument>
55+
</arguments>
56+
</type>
57+
<type name="Magento\Csp\Model\Collector\CspWhitelistXmlCollector">
58+
<arguments>
59+
<argument name="configReader" xsi:type="object">Magento\Csp\Model\Collector\CspWhitelistXml\Data</argument>
60+
</arguments>
61+
</type>
5262
<type name="Magento\Framework\View\TemplateEngine\Php">
5363
<plugin name="csp_helper_plugin" type="Magento\Csp\Plugin\TemplateRenderingPlugin" />
5464
</type>

0 commit comments

Comments
 (0)