Skip to content

Commit 033fa29

Browse files
Merge branch 'AC-12654' into cia-2.4.8-beta1-develop-bugfix-09032024
2 parents 42074ff + f9974b9 commit 033fa29

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class Product extends AbstractEntity
5656
private const COL_NAME_FORMAT = '/[\x00-\x1F\x7F]/';
5757
public const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types';
5858

59+
/**
60+
* Filter chain const
61+
*/
62+
private const FILTER_CHAIN = "php://filter";
63+
5964
/**
6065
* Size of bunch - part of products to save in one step.
6166
*/
@@ -775,6 +780,11 @@ class Product extends AbstractEntity
775780
*/
776781
private ?SkuStorage $skuStorage;
777782

783+
/**
784+
* @var File|null
785+
*/
786+
private ?File $fileDriver;
787+
778788
/**
779789
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
780790
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -950,6 +960,8 @@ public function __construct(
950960
->get(ProductRepositoryInterface::class);
951961
$this->stockItemProcessor = $stockItemProcessor ?? ObjectManager::getInstance()
952962
->get(StockItemProcessorInterface::class);
963+
$this->fileDriver = $fileDriver ?? ObjectManager::getInstance()
964+
->get(File::class);
953965
}
954966

955967
/**
@@ -2126,7 +2138,10 @@ private function getRemoteFileContent(string $filename): string
21262138
{
21272139
try {
21282140
// phpcs:ignore Magento2.Functions.DiscouragedFunction
2129-
$content = file_get_contents($filename);
2141+
if (stripos($filename, self::FILTER_CHAIN) !== false) {
2142+
return '';
2143+
}
2144+
$content = $this->fileDriver->fileGetContents($filename);
21302145
} catch (\Exception $e) {
21312146
$content = false;
21322147
}

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
*/
2121
class Validator extends AbstractValidator implements RowValidatorInterface
2222
{
23+
/**
24+
* Filter chain const
25+
*/
26+
private const FILTER_CHAIN = "php://filter";
27+
2328
/**
2429
* @var RowValidatorInterface[]|AbstractValidator[]
2530
*/
@@ -91,6 +96,10 @@ public function __construct(
9196
protected function textValidation($attrCode, $type)
9297
{
9398
$val = $this->string->cleanString($this->_rowData[$attrCode]);
99+
if (stripos($val, self::FILTER_CHAIN) !== false) {
100+
$this->_addMessages([RowValidatorInterface::ERROR_INVALID_ATTRIBUTE_TYPE]);
101+
return false;
102+
}
94103
if ($type == 'text') {
95104
$valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
96105
} elseif ($attrCode == Product::COL_SKU) {

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,4 +2252,18 @@ public static function valuesDataProvider(): array
22522252
]
22532253
];
22542254
}
2255+
2256+
/**
2257+
* get remote file content
2258+
*/
2259+
public function testGetRemoteFileContent()
2260+
{
2261+
$reflector = new \ReflectionClass($this->importProduct);
2262+
$property = $reflector->getMethod('getRemoteFileContent');
2263+
$property->setAccessible(true);
2264+
$this->assertEquals(
2265+
'',
2266+
$property->invokeArgs($this->importProduct, ['php://filter'])
2267+
);
2268+
}
22552269
}

0 commit comments

Comments
 (0)