allowedPaths = [ $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], 'uploads/', 'typo3temp/', PathUtility::stripPathSitePrefix(Environment::getBackendPath()) . '/ext/', PathUtility::stripPathSitePrefix(Environment::getFrameworkBasePath()) . '/', PathUtility::stripPathSitePrefix(Environment::getExtensionsPath()) . '/', ]; if (!empty($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'])) { $paths = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'], true); foreach ($paths as $path) { if (is_string($path)) { $this->allowedPaths[] = $path; } } } } /** * Returns the reference used for the frontend inclusion, checks against allowed paths for inclusion. * * @param string $originalFileName * @return string Resulting filename, is either a full absolute URL or a relative path. */ public function sanitize(string $originalFileName): string { $file = trim($originalFileName); if (empty($file)) { throw new InvalidFileNameException('Empty file name given', 1530169746); } if (strpos($file, '../') !== false) { throw new InvalidPathException('File path "' . $file . '" contains illegal string "../"', 1530169814); } // if this is an URL, it can be returned directly $urlScheme = parse_url($file, PHP_URL_SCHEME); if ($urlScheme === 'https' || $urlScheme === 'http' || is_file(Environment::getPublicPath() . '/' . $file)) { return $file; } // this call also resolves EXT:myext/ files $file = GeneralUtility::getFileAbsFileName($file); if (!$file || is_dir($file)) { throw new FileDoesNotExistException('File "' . $originalFileName . '" was not found', 1530169845); } $file = PathUtility::stripPathSitePrefix($file); // Check if the found file is in the allowed paths foreach ($this->allowedPaths as $allowedPath) { if (strpos((string)$file, (string)$allowedPath, 0) === 0) { return $file; } } throw new InvalidFileException('"' . $file . '" was not located in the allowed paths', 1530169955); } }