|
11 | 11 | * source code.
|
12 | 12 | */
|
13 | 13 |
|
14 |
| -use enshrined\svgSanitize\Sanitizer; |
15 | 14 | use Neos\Flow\Annotations as Flow;
|
16 | 15 | use Neos\Flow\Log\Utility\LogEnvironment;
|
17 | 16 | use Neos\Flow\ObjectManagement\ObjectManagerInterface;
|
18 | 17 | use Neos\Flow\Persistence\PersistenceManagerInterface;
|
19 |
| -use Neos\Utility\MediaTypes; |
20 | 18 | use Neos\Utility\ObjectAccess;
|
21 | 19 | use Neos\Flow\ResourceManagement\Storage\StorageInterface;
|
22 | 20 | use Neos\Flow\ResourceManagement\Storage\WritableStorageInterface;
|
@@ -162,30 +160,14 @@ public function importResource($source, $collectionName = ResourceManager::DEFAU
|
162 | 160 | $collection = $this->collections[$collectionName];
|
163 | 161 |
|
164 | 162 | try {
|
165 |
| - if (is_resource($source)) { |
166 |
| - $mediaType = MediaTypes::getMediaTypeFromResource($source); |
167 |
| - if ($this->isSanitizingRequired($mediaType)) { |
168 |
| - $content = stream_get_contents($source); |
169 |
| - $resource = $this->importResourceFromContent($content, '', $collectionName, $forcedPersistenceObjectIdentifier); |
170 |
| - } else { |
171 |
| - $resource = $collection->importResource($source); |
172 |
| - } |
173 |
| - } else { |
174 |
| - $resource = fopen($source, 'rb'); |
175 |
| - $mediaType = MediaTypes::getMediaTypeFromResource($resource); |
176 |
| - fclose($resource); |
177 |
| - if ($this->isSanitizingRequired($mediaType)) { |
178 |
| - $content = file_get_contents($source); |
179 |
| - $resource = $this->importResourceFromContent($content, '', $collectionName, $forcedPersistenceObjectIdentifier); |
180 |
| - } else { |
181 |
| - $resource = $collection->importResource($source); |
182 |
| - } |
183 |
| - $pathInfo = UnicodeFunctions::pathinfo($source); |
184 |
| - $resource->setFilename($pathInfo['basename']); |
185 |
| - } |
| 163 | + $resource = $collection->importResource($source); |
186 | 164 | if ($forcedPersistenceObjectIdentifier !== null) {
|
187 | 165 | ObjectAccess::setProperty($resource, 'Persistence_Object_Identifier', $forcedPersistenceObjectIdentifier, true);
|
188 | 166 | }
|
| 167 | + if (!is_resource($source)) { |
| 168 | + $pathInfo = UnicodeFunctions::pathinfo($source); |
| 169 | + $resource->setFilename($pathInfo['basename']); |
| 170 | + } |
189 | 171 | } catch (Exception $exception) {
|
190 | 172 | throw new Exception(sprintf('Importing a file into the resource collection "%s" failed: %s', $collectionName, $exception->getMessage()), 1375197120, $exception);
|
191 | 173 | }
|
@@ -224,11 +206,6 @@ public function importResourceFromContent($content, $filename, $collectionName =
|
224 | 206 | throw new Exception(sprintf('Tried to import a file into the resource collection "%s" but no such collection exists. Please check your settings and the code which triggered the import.', $collectionName), 1380878131);
|
225 | 207 | }
|
226 | 208 |
|
227 |
| - $mediaType = MediaTypes::getMediaTypeFromFileContent($content); |
228 |
| - if ($this->isSanitizingRequired($mediaType)) { |
229 |
| - $content = $this->sanitizeImportedFileContent($mediaType, $content, $filename); |
230 |
| - } |
231 |
| - |
232 | 209 | /* @var CollectionInterface $collection */
|
233 | 210 | $collection = $this->collections[$collectionName];
|
234 | 211 |
|
@@ -631,44 +608,6 @@ protected function initializeCollections()
|
631 | 608 | }
|
632 | 609 | }
|
633 | 610 |
|
634 |
| - /** |
635 |
| - * Decide weather the given media-type has to be sanitized |
636 |
| - * for now this only checks svg file to solve the issue here https://nvd.nist.gov/vuln/detail/CVE-2023-37611 |
637 |
| - * |
638 |
| - * @todo create a feature from this and allow to register code for sanitizing file content before importing |
639 |
| - */ |
640 |
| - protected function isSanitizingRequired(string $mediaType): bool |
641 |
| - { |
642 |
| - return $mediaType === 'image/svg+xml'; |
643 |
| - } |
644 |
| - |
645 |
| - /** |
646 |
| - * Sanitize file content and remove content that is suspicious |
647 |
| - * for now this only checks svg file to solve the issue here https://nvd.nist.gov/vuln/detail/CVE-2023-37611 |
648 |
| - * |
649 |
| - * @todo create a feature from this and allow to register code for sanitizing file content before importing |
650 |
| - */ |
651 |
| - protected function sanitizeImportedFileContent(string $mediaType, string $content, $filename = ''): string |
652 |
| - { |
653 |
| - if ($mediaType === 'image/svg+xml') { |
654 |
| - // @todo: Simplify again when https://github.com/darylldoyle/svg-sanitizer/pull/90 is merged and released. |
655 |
| - $previousXmlErrorHandling = libxml_use_internal_errors(true); |
656 |
| - $sanitizer = new Sanitizer(); |
657 |
| - $sanitizedContent = $sanitizer->sanitize($content); |
658 |
| - libxml_clear_errors(); |
659 |
| - libxml_use_internal_errors($previousXmlErrorHandling); |
660 |
| - $issues = $sanitizer->getXmlIssues(); |
661 |
| - if ($issues && count($issues) > 0) { |
662 |
| - if ($sanitizedContent === false) { |
663 |
| - throw new Exception('Sanitizing of suspicious file "' . $filename . '" failed during import.', 1695395560); |
664 |
| - } |
665 |
| - $content = $sanitizedContent; |
666 |
| - $this->logger->warning(sprintf('Imported file "%s" contained suspicious content and was sanitized.', $filename), $issues); |
667 |
| - } |
668 |
| - } |
669 |
| - return $content; |
670 |
| - } |
671 |
| - |
672 | 611 | /**
|
673 | 612 | * Prepare an uploaded file to be imported as resource object. Will check the validity of the file,
|
674 | 613 | * move it outside of upload folder if open_basedir is enabled and check the filename.
|
|
0 commit comments