Skip to content

Commit 361a230

Browse files
MAGETWO-59809: Scrub sensitive data during app:dump
1 parent a79389c commit 361a230

File tree

52 files changed

+1974
-104
lines changed

Some content is hidden

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

52 files changed

+1974
-104
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@
1616
<argument name="storage" xsi:type="object">Magento\Authorizenet\Model\Directpost\Session\Storage</argument>
1717
</arguments>
1818
</type>
19+
<type name="Magento\Config\Model\Config\Export\ExcludeList">
20+
<arguments>
21+
<argument name="configs" xsi:type="array">
22+
<item name="payment/authorizenet_directpost/login" xsi:type="string">1</item>
23+
<item name="payment/authorizenet_directpost/trans_key" xsi:type="string">1</item>
24+
<item name="payment/authorizenet_directpost/trans_md5" xsi:type="string">1</item>
25+
<item name="payment/authorizenet_directpost/merchant_email" xsi:type="string">1</item>
26+
</argument>
27+
</arguments>
28+
</type>
1929
</config>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,22 @@
214214
</argument>
215215
</arguments>
216216
</type>
217+
<type name="Magento\Config\Model\Config\Export\ExcludeList">
218+
<arguments>
219+
<argument name="configs" xsi:type="array">
220+
<item name="trans_email/ident_general/name" xsi:type="string">1</item>
221+
<item name="trans_email/ident_general/email" xsi:type="string">1</item>
222+
<item name="trans_email/ident_sales/name" xsi:type="string">1</item>
223+
<item name="trans_email/ident_sales/email" xsi:type="string">1</item>
224+
<item name="trans_email/ident_support/name" xsi:type="string">1</item>
225+
<item name="trans_email/ident_support/email" xsi:type="string">1</item>
226+
<item name="trans_email/ident_custom1/name" xsi:type="string">1</item>
227+
<item name="trans_email/ident_custom1/email" xsi:type="string">1</item>
228+
<item name="trans_email/ident_custom2/name" xsi:type="string">1</item>
229+
<item name="trans_email/ident_custom2/email" xsi:type="string">1</item>
230+
<item name="admin/url/custom" xsi:type="string">1</item>
231+
<item name="admin/url/custom_path" xsi:type="string">1</item>
232+
</argument>
233+
</arguments>
234+
</type>
217235
</config>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,16 @@
434434
</arguments>
435435
</type>
436436

437+
<type name="Magento\Config\Model\Config\Export\ExcludeList">
438+
<arguments>
439+
<argument name="configs" xsi:type="array">
440+
<item name="payment/braintree/merchant_id" xsi:type="string">1</item>
441+
<item name="payment/braintree/public_key" xsi:type="string">1</item>
442+
<item name="payment/braintree/private_key" xsi:type="string">1</item>
443+
<item name="payment/braintree/merchant_account_id" xsi:type="string">1</item>
444+
<item name="payment/braintree/kount_id" xsi:type="string">1</item>
445+
<item name="payment/braintree_paypal/merchant_name_override" xsi:type="string">1</item>
446+
</argument>
447+
</arguments>
448+
</type>
437449
</config>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@
4242
</argument>
4343
</arguments>
4444
</type>
45+
<type name="Magento\Config\Model\Config\Export\ExcludeList">
46+
<arguments>
47+
<argument name="configs" xsi:type="array">
48+
<item name="checkout/payment_failed/copy_to" xsi:type="string">1</item>
49+
</argument>
50+
</arguments>
51+
</type>
4552
</config>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\App\Config\Source;
7+
8+
use Magento\Config\Model\Config\Export\ExcludeList;
9+
use Magento\Framework\App\Config\ConfigSourceInterface;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
12+
class DumpConfigSourceAggregated implements DumpConfigSourceInterface
13+
{
14+
/**
15+
* @var ExcludeList
16+
*/
17+
private $excludeList;
18+
19+
/**
20+
* @var ConfigSourceInterface[]
21+
*/
22+
private $sources;
23+
24+
/**
25+
* @var array
26+
*/
27+
private $excludedFields;
28+
29+
/**
30+
* @var array
31+
*/
32+
private $data;
33+
34+
/**
35+
* @param ExcludeList $excludeList
36+
* @param array $sources
37+
*/
38+
public function __construct(ExcludeList $excludeList, array $sources = [])
39+
{
40+
$this->excludeList = $excludeList;
41+
$this->sources = $sources;
42+
}
43+
44+
/**
45+
* Retrieve aggregated configuration from all available sources.
46+
*
47+
* @param string $path
48+
* @return array
49+
*/
50+
public function get($path = '')
51+
{
52+
$path = (string)$path;
53+
$data = [];
54+
55+
if (isset($this->data[$path])) {
56+
return $this->data[$path];
57+
}
58+
59+
$this->sortSources();
60+
61+
foreach ($this->sources as $sourceConfig) {
62+
/** @var ConfigSourceInterface $source */
63+
$source = $sourceConfig['source'];
64+
$data = array_replace_recursive($data, $source->get($path));
65+
}
66+
67+
$this->excludedFields = [];
68+
$this->filterChain($path, $data);
69+
70+
return $this->data[$path] = $data;
71+
}
72+
73+
/**
74+
* Recursive filtering of sensitive data
75+
*
76+
* @param string $path
77+
* @param array $data
78+
*/
79+
private function filterChain($path, &$data)
80+
{
81+
foreach ($data as $subKey => &$subData) {
82+
$newPath = $path ? $path . '/' . $subKey : $subKey;
83+
$filteredPath = $this->filterPath($newPath);
84+
85+
if (
86+
$filteredPath
87+
&& !is_array($data[$subKey])
88+
&& $this->excludeList->isPresent($filteredPath)
89+
) {
90+
$this->excludedFields[$newPath] = $filteredPath;
91+
92+
unset($data[$subKey]);
93+
} elseif (is_array($subData)) {
94+
$this->filterChain($newPath, $subData);
95+
}
96+
}
97+
}
98+
99+
/**
100+
* Eliminating scope info from path
101+
*
102+
* @param string $path
103+
* @return null|string
104+
*/
105+
private function filterPath($path)
106+
{
107+
$parts = explode('/', $path);
108+
109+
// Check if there are enough parts to recognize scope
110+
if (count($parts) < 3) {
111+
return null;
112+
}
113+
114+
if ($parts[0] === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
115+
unset($parts[0]);
116+
} else {
117+
unset($parts[0], $parts[1]);
118+
}
119+
120+
return implode('/', $parts);
121+
}
122+
123+
/**
124+
* Sort sources
125+
*
126+
* @return void
127+
*/
128+
private function sortSources()
129+
{
130+
uasort($this->sources, function ($firstItem, $secondItem) {
131+
return $firstItem['sortOrder'] > $secondItem['sortOrder'];
132+
});
133+
}
134+
135+
/**
136+
* Retrieves list of field paths were excluded from config dump
137+
* @return array
138+
*/
139+
public function getExcludedFields()
140+
{
141+
$this->get();
142+
143+
$fields = array_values($this->excludedFields);
144+
$fields = array_unique($fields);
145+
146+
return $fields;
147+
}
148+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\App\Config\Source;
7+
8+
use Magento\Framework\App\Config\ConfigSourceInterface;
9+
10+
/**
11+
* Interface DumpConfigSourceInterface
12+
*/
13+
interface DumpConfigSourceInterface extends ConfigSourceInterface
14+
{
15+
/**
16+
* Retrieves list of field paths were excluded from config dump
17+
*
18+
* @return array
19+
*/
20+
public function getExcludedFields();
21+
}

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\App\Config\ConfigTypeInterface;
99
use Magento\Framework\App\Config\ConfigSourceInterface;
1010
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
11+
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
1112
use Magento\Framework\Cache\FrontendInterface;
1213
use Magento\Framework\DataObject;
1314
use Magento\Store\Model\Config\Processor\Fallback;
@@ -38,6 +39,11 @@ class System implements ConfigTypeInterface
3839
*/
3940
private $postProcessor;
4041

42+
/**
43+
* @var PreProcessorInterface
44+
*/
45+
private $preProcessor;
46+
4147
/**
4248
* @var FrontendInterface
4349
*/
@@ -59,17 +65,20 @@ class System implements ConfigTypeInterface
5965
* @param PostProcessorInterface $postProcessor
6066
* @param Fallback $fallback
6167
* @param FrontendInterface $cache
68+
* @param PreProcessorInterface $preProcessor
6269
* @param int $cachingNestedLevel
6370
*/
6471
public function __construct(
6572
ConfigSourceInterface $source,
6673
PostProcessorInterface $postProcessor,
6774
Fallback $fallback,
6875
FrontendInterface $cache,
76+
PreProcessorInterface $preProcessor,
6977
$cachingNestedLevel = 1
7078
) {
7179
$this->source = $source;
7280
$this->postProcessor = $postProcessor;
81+
$this->preProcessor = $preProcessor;
7382
$this->cache = $cache;
7483
$this->cachingNestedLevel = $cachingNestedLevel;
7584
$this->fallback = $fallback;
@@ -86,7 +95,9 @@ public function get($path = '')
8695
if (!$this->data) {
8796
$data = $this->cache->load(self::CONFIG_TYPE);
8897
if (!$data) {
89-
$data = $this->fallback->process($this->source->get());
98+
$data = $this->preProcessor->process($this->source->get());
99+
$this->data = new DataObject($data);
100+
$data = $this->fallback->process($data);
90101
$this->data = new DataObject($data);
91102
$data = $this->postProcessor->process($data);
92103
$this->data = new DataObject($data);

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
1011
use Magento\Framework\App\DeploymentConfig;
1112
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\DataObject;
1214

1315
/**
1416
* System config form block
@@ -333,6 +335,16 @@ protected function _initElement(
333335
) {
334336
$inherit = true;
335337
$data = $this->getAppConfigDataValue($path);
338+
339+
$placeholderValue = $this->getSettingChecker()->getPlaceholderValue(
340+
$path,
341+
$this->getScope(),
342+
$this->getStringScopeCode()
343+
);
344+
345+
if ($placeholderValue) {
346+
$data = $placeholderValue;
347+
}
336348
if ($data === null) {
337349
if (array_key_exists($path, $this->_configData)) {
338350
$data = $this->_configData[$path];
@@ -373,9 +385,7 @@ protected function _initElement(
373385
$sharedClass = $this->_getSharedCssClass($field);
374386
$requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
375387

376-
$isReadOnly = $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getScopeCode());
377-
$canUseDefault = $this->canUseDefaultValue($field->showInDefault());
378-
$canUseWebsite = $this->canUseWebsiteValue($field->showInWebsite());
388+
$isReadOnly = $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
379389
$formField = $fieldset->addField(
380390
$elementId,
381391
$field->getType(),
@@ -392,8 +402,8 @@ protected function _initElement(
392402
'scope' => $this->getScope(),
393403
'scope_id' => $this->getScopeId(),
394404
'scope_label' => $this->getScopeLabel($field),
395-
'can_use_default_value' => $canUseDefault,
396-
'can_use_website_value' => $canUseWebsite,
405+
'can_use_default_value' => $this->canUseDefaultValue($field->showInDefault()),
406+
'can_use_website_value' => $this->canUseWebsiteValue($field->showInWebsite()),
397407
'can_restore_to_default' => $this->isCanRestoreToDefault($field->canRestore()),
398408
'disabled' => $isReadOnly,
399409
'is_disable_inheritance' => $isReadOnly
@@ -413,6 +423,28 @@ protected function _initElement(
413423
$formField->setRenderer($fieldRenderer);
414424
}
415425

426+
/**
427+
* Retrieve Scope string code
428+
*
429+
* @return string
430+
*/
431+
private function getStringScopeCode()
432+
{
433+
$scopeCode = $this->getData('scope_string_code');
434+
if (null === $scopeCode) {
435+
if ($this->getStoreCode()) {
436+
$scopeCode = $this->_storeManager->getStore($this->getStoreCode())->getCode();
437+
} elseif ($this->getWebsiteCode()) {
438+
$scopeCode = $this->_storeManager->getWebsite($this->getWebsiteCode())->getCode();
439+
} else {
440+
$scopeCode = '';
441+
}
442+
$this->setScopeStringCode($scopeCode);
443+
}
444+
445+
return $scopeCode;
446+
}
447+
416448
/**
417449
* Populate dependencies block
418450
*
@@ -748,14 +780,13 @@ private function getAppConfigDataValue($path)
748780
{
749781
$appConfig = $this->getAppConfig()->get(System::CONFIG_TYPE);
750782
$scope = $this->getScope();
751-
$scopeId = $this->getScopeId();
752-
if ($scope === 'default') {
753-
$data = isset($appConfig[$scope][$path]) ? $appConfig[$scope][$path] : null;
783+
$scopeCode = $this->getStringScopeCode();
784+
785+
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
786+
$data = new DataObject(isset($appConfig[$scope]) ? $appConfig[$scope] : []);
754787
} else {
755-
$data = isset($appConfig[$scope][$scopeId][$path])
756-
? $appConfig[$scope][$scopeId][$path]
757-
: null;
788+
$data = new DataObject(isset($appConfig[$scope][$scopeCode]) ? $appConfig[$scope][$scopeCode] : []);
758789
}
759-
return $data;
790+
return $data->getData($path);
760791
}
761792
}

0 commit comments

Comments
 (0)