Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TYPO3 13 compatibility #58

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ jobs:
fast_finish: true
include:
- stage: test
php: 7.2
env: TYPO3=^8.7
php: 8.2
env: TYPO3=^12.4
- stage: test
php: 7.2
env: TYPO3=^9.5
php: 8.2
env: TYPO3=^13.4

- stage: publish to ter
if: tag IS present
php: 7.2
php: 8.2
before_install: skip
install: skip
before_script: skip
Expand Down
222 changes: 0 additions & 222 deletions Classes/JumpUrlProcessor.php

This file was deleted.

48 changes: 35 additions & 13 deletions Classes/Middleware/JumpUrlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\TypoScript\PageTsConfig;
use TYPO3\CMS\Core\TypoScript\PageTsConfigFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down Expand Up @@ -69,7 +73,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
// Regular jump URL
$this->validateIfJumpUrlRedirectIsAllowed($jumpUrl, $juHash);
return $this->redirectToJumpUrl($jumpUrl);
return $this->redirectToJumpUrl($jumpUrl, $request);
}
return $handler->handle($request);
}
Expand All @@ -81,9 +85,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
* @throws \Exception
* @return ResponseInterface
*/
protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
protected function redirectToJumpUrl(string $jumpUrl, ServerRequestInterface $request): ResponseInterface
{
$pageTSconfig = $this->getTypoScriptFrontendController()->getPagesTSconfig();
$pageTSconfig = $this->getPageTsConfig($request);
$pageTSconfig = array_key_exists('TSFE.', $pageTSconfig) && is_array($pageTSconfig['TSFE.'] ?? false) ? $pageTSconfig['TSFE.'] : [];

// Allow sections in links
Expand All @@ -94,6 +98,30 @@ protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
return new RedirectResponse($jumpUrl, $statusCode);
}

/**
* @param ServerRequestInterface $request
* @return array
* @throws \JsonException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
protected function getPageTsConfig(ServerRequestInterface $request): array
{
$pageInformation = $request->getAttribute('frontend.page.information');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change only works in v13, but the changes you make in composer.json says that the code should also stay compatible with older versions.

How about we make it work for v12 and v13 at the same time and drop the older versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go ...

$id = $pageInformation->getId();
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$pageTsConfig = $runtimeCache->get('pageTsConfig-' . $id);
if ($pageTsConfig instanceof PageTsConfig) {
return $pageTsConfig->getPageTsConfigArray();
}
$fullRootLine = $pageInformation->getRootLine();
ksort($fullRootLine);
$site = $request->getAttribute('site') ?? new NullSite();
$pageTsConfigFactory = GeneralUtility::makeInstance(PageTsConfigFactory::class);
$pageTsConfig = $pageTsConfigFactory->create($fullRootLine, $site);
$runtimeCache->set('pageTsConfig-' . $id, $pageTsConfig);
return $pageTsConfig->getPageTsConfigArray();
}

/**
* If the submitted hash is correct and the user has access to the
* related content element the contents of the submitted file will
Expand Down Expand Up @@ -126,15 +154,9 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio

// Check if requested file accessable
$fileAccessAllowed = false;
if ((new Typo3Version())->getMajorVersion() < 11) {
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
&& GeneralUtility::verifyFilenameAgainstDenyPattern($absoluteFileName)
&& !GeneralUtility::isFirstPartOfStr($absoluteFileName, Environment::getLegacyConfigPath());
} else {
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
&& GeneralUtility::makeInstance(FileNameValidator::class)->isValid($absoluteFileName)
&& !str_starts_with($absoluteFileName, Environment::getLegacyConfigPath());
}
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
&& GeneralUtility::makeInstance(FileNameValidator::class)->isValid($absoluteFileName)
&& !str_starts_with($absoluteFileName, Environment::getLegacyConfigPath());
if (!$fileAccessAllowed) {
throw new \Exception('The requested file was not allowed to be accessed through Jump URL. The path or file is not allowed.', 1294585194);
}
Expand All @@ -157,7 +179,7 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio
protected function isLocationDataValid(string $locationData): bool
{
$isValidLocationData = false;
list($pageUid, $table, $recordUid) = explode(':', $locationData);
[$pageUid, $table, $recordUid] = explode(':', $locationData);
$pageRepository = $this->getTypoScriptFrontendController()->sys_page;
if (empty($table) || $pageRepository->checkRecord($table, $recordUid, true)) {
// This check means that a record is checked only if the locationData has a value for a
Expand Down
Loading