Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b335fe7

Browse files
committed
Merge branch 'MAGETWO-75418' into 2.3-develop-pr2
2 parents 57067bd + 64acc06 commit b335fe7

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

app/code/Magento/Cms/Helper/Wysiwyg/Images.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99

1010
/**
11-
* Wysiwyg Images Helper
11+
* Wysiwyg Images Helper.
12+
*
13+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1214
*/
1315
class Images extends \Magento\Framework\App\Helper\AbstractHelper
1416
{
@@ -156,17 +158,23 @@ public function convertPathToId($path)
156158
}
157159

158160
/**
159-
* Decode HTML element id
161+
* Decode HTML element id.
160162
*
161163
* @param string $id
162164
* @return string
165+
* @throws \InvalidArgumentException When path contains restricted symbols.
163166
*/
164167
public function convertIdToPath($id)
165168
{
166169
if ($id === \Magento\Theme\Helper\Storage::NODE_ROOT) {
167170
return $this->getStorageRoot();
168171
} else {
169-
return $this->getStorageRoot() . $this->idDecode($id);
172+
$path = $this->getStorageRoot() . $this->idDecode($id);
173+
if (preg_match('/\.\.(\\\|\/)/', $path)) {
174+
throw new \InvalidArgumentException('Path is invalid');
175+
}
176+
177+
return $path;
170178
}
171179
}
172180

app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function setUp()
110110
->willReturnMap(
111111
[
112112
[WysiwygConfig::IMAGE_DIRECTORY, null, $this->getAbsolutePath(WysiwygConfig::IMAGE_DIRECTORY)],
113-
[null, null, $this->getAbsolutePath(null)]
113+
[null, null, $this->getAbsolutePath(null)],
114114
]
115115
);
116116

@@ -124,7 +124,7 @@ protected function setUp()
124124
[
125125
'clearWebsiteCache', 'getDefaultStoreView', 'getGroup', 'getGroups',
126126
'getStore', 'getStores', 'getWebsite', 'getWebsites', 'hasSingleStore',
127-
'isSingleStoreMode', 'reinitStores', 'setCurrentStore', 'setIsSingleStoreModeAllowed'
127+
'isSingleStoreMode', 'reinitStores', 'setCurrentStore', 'setIsSingleStoreModeAllowed',
128128
]
129129
)
130130
->disableOriginalConstructor()
@@ -229,7 +229,7 @@ public function providerConvertIdToPath()
229229
{
230230
return [
231231
['', ''],
232-
['/test_path', 'L3Rlc3RfcGF0aA--']
232+
['/test_path', 'L3Rlc3RfcGF0aA--'],
233233
];
234234
}
235235

@@ -239,6 +239,15 @@ public function testConvertIdToPathNodeRoot()
239239
$this->assertEquals($this->imagesHelper->getStorageRoot(), $this->imagesHelper->convertIdToPath($pathId));
240240
}
241241

242+
/**
243+
* @expectedException \InvalidArgumentException
244+
* @expectedExceptionMessage Path is invalid
245+
*/
246+
public function testConvertIdToPathInvalid()
247+
{
248+
$this->imagesHelper->convertIdToPath('Ly4uLy4uLy4uLy4uLy4uL3dvcms-');
249+
}
250+
242251
/**
243252
* @param string $fileName
244253
* @param int $maxLength
@@ -258,7 +267,7 @@ public function providerShortFilename()
258267
return [
259268
['test', 3, 'tes...'],
260269
['test', 4, 'test'],
261-
['test', 20, 'test']
270+
['test', 20, 'test'],
262271
];
263272
}
264273

@@ -280,7 +289,7 @@ public function providerShortFilenameDefaultMaxLength()
280289
return [
281290
['Mini text', 'Mini text'],
282291
['20 symbols are here', '20 symbols are here'],
283-
['Some text for this unit test', 'Some text for this u...']
292+
['Some text for this unit test', 'Some text for this u...'],
284293
];
285294
}
286295

@@ -319,7 +328,7 @@ public function providerIsUsingStaticUrlsAllowed()
319328
{
320329
return [
321330
[true],
322-
[false]
331+
[false],
323332
];
324333
}
325334

@@ -346,7 +355,7 @@ public function testGetCurrentPath($pathId, $expectedPath, $isExist)
346355
[
347356
['/../wysiwyg/test_path', true],
348357
['/../wysiwyg/my.jpg', false],
349-
['/../wysiwyg', true]
358+
['/../wysiwyg', true],
350359
]
351360
);
352361
$this->directoryWriteMock->expects($this->any())
@@ -397,7 +406,7 @@ public function providerGetCurrentPath()
397406
[null, 'PATH/wysiwyg', true],
398407
['L3Rlc3RfcGF0aA--', 'PATH/wysiwyg/test_path', false],
399408
['L215LmpwZw--', 'PATH/wysiwyg', false],
400-
[null, 'PATH/wysiwyg', false]
409+
[null, 'PATH/wysiwyg', false],
401410
];
402411
}
403412

@@ -450,15 +459,15 @@ public function providerGetImageHtmlDeclarationRenderingAsTag()
450459
'test.png',
451460
true,
452461
null,
453-
'<img src="http://localhost/test.png" alt="" />'
462+
'<img src="http://localhost/test.png" alt="" />',
454463
],
455464
[
456465
'http://localhost',
457466
'test.png',
458467
false,
459468
'{{media url=&quot;/test.png&quot;}}',
460-
'<img src="{{media url=&quot;/test.png&quot;}}" alt="" />'
461-
]
469+
'<img src="{{media url=&quot;/test.png&quot;}}" alt="" />',
470+
],
462471
];
463472
}
464473

@@ -492,7 +501,7 @@ public function providerGetImageHtmlDeclaration()
492501
{
493502
return [
494503
['http://localhost', 'test.png', true, 'http://localhost/test.png'],
495-
['http://localhost', 'test.png', false, '{{media url="/test.png"}}']
504+
['http://localhost', 'test.png', false, '{{media url="/test.png"}}'],
496505
];
497506
}
498507

0 commit comments

Comments
 (0)