19
19
use Psr \Http \Message \ServerRequestInterface ;
20
20
use Psr \Http \Server \MiddlewareInterface ;
21
21
use Psr \Http \Server \RequestHandlerInterface ;
22
+ use TYPO3 \CMS \Core \Cache \CacheManager ;
22
23
use TYPO3 \CMS \Core \Core \Environment ;
23
24
use TYPO3 \CMS \Core \Http \RedirectResponse ;
24
25
use TYPO3 \CMS \Core \Information \Typo3Version ;
25
26
use TYPO3 \CMS \Core \Resource \ResourceFactory ;
26
27
use TYPO3 \CMS \Core \Resource \Security \FileNameValidator ;
28
+ use TYPO3 \CMS \Core \Site \Entity \NullSite ;
27
29
use TYPO3 \CMS \Core \TimeTracker \TimeTracker ;
30
+ use TYPO3 \CMS \Core \TypoScript \PageTsConfig ;
31
+ use TYPO3 \CMS \Core \TypoScript \PageTsConfigFactory ;
28
32
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
29
33
use TYPO3 \CMS \Frontend \Controller \TypoScriptFrontendController ;
30
34
@@ -69,7 +73,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
69
73
}
70
74
// Regular jump URL
71
75
$ this ->validateIfJumpUrlRedirectIsAllowed ($ jumpUrl , $ juHash );
72
- return $ this ->redirectToJumpUrl ($ jumpUrl );
76
+ return $ this ->redirectToJumpUrl ($ jumpUrl, $ request );
73
77
}
74
78
return $ handler ->handle ($ request );
75
79
}
@@ -81,9 +85,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
81
85
* @throws \Exception
82
86
* @return ResponseInterface
83
87
*/
84
- protected function redirectToJumpUrl (string $ jumpUrl ): ResponseInterface
88
+ protected function redirectToJumpUrl (string $ jumpUrl, ServerRequestInterface $ request ): ResponseInterface
85
89
{
86
- $ pageTSconfig = $ this ->getTypoScriptFrontendController ()-> getPagesTSconfig ( );
90
+ $ pageTSconfig = $ this ->getPageTsConfig ( $ request );
87
91
$ pageTSconfig = array_key_exists ('TSFE. ' , $ pageTSconfig ) && is_array ($ pageTSconfig ['TSFE. ' ] ?? false ) ? $ pageTSconfig ['TSFE. ' ] : [];
88
92
89
93
// Allow sections in links
@@ -94,6 +98,30 @@ protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
94
98
return new RedirectResponse ($ jumpUrl , $ statusCode );
95
99
}
96
100
101
+ /**
102
+ * @param ServerRequestInterface $request
103
+ * @return array
104
+ * @throws \JsonException
105
+ * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
106
+ */
107
+ protected function getPageTsConfig (ServerRequestInterface $ request ): array
108
+ {
109
+ $ pageInformation = $ request ->getAttribute ('frontend.page.information ' );
110
+ $ id = $ pageInformation ->getId ();
111
+ $ runtimeCache = GeneralUtility::makeInstance (CacheManager::class)->getCache ('runtime ' );
112
+ $ pageTsConfig = $ runtimeCache ->get ('pageTsConfig- ' . $ id );
113
+ if ($ pageTsConfig instanceof PageTsConfig) {
114
+ return $ pageTsConfig ->getPageTsConfigArray ();
115
+ }
116
+ $ fullRootLine = $ pageInformation ->getRootLine ();
117
+ ksort ($ fullRootLine );
118
+ $ site = $ request ->getAttribute ('site ' ) ?? new NullSite ();
119
+ $ pageTsConfigFactory = GeneralUtility::makeInstance (PageTsConfigFactory::class);
120
+ $ pageTsConfig = $ pageTsConfigFactory ->create ($ fullRootLine , $ site );
121
+ $ runtimeCache ->set ('pageTsConfig- ' . $ id , $ pageTsConfig );
122
+ return $ pageTsConfig ->getPageTsConfigArray ();
123
+ }
124
+
97
125
/**
98
126
* If the submitted hash is correct and the user has access to the
99
127
* related content element the contents of the submitted file will
@@ -126,15 +154,9 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio
126
154
127
155
// Check if requested file accessable
128
156
$ fileAccessAllowed = false ;
129
- if ((new Typo3Version ())->getMajorVersion () < 11 ) {
130
- $ fileAccessAllowed = GeneralUtility::isAllowedAbsPath ($ absoluteFileName )
131
- && GeneralUtility::verifyFilenameAgainstDenyPattern ($ absoluteFileName )
132
- && !GeneralUtility::isFirstPartOfStr ($ absoluteFileName , Environment::getLegacyConfigPath ());
133
- } else {
134
- $ fileAccessAllowed = GeneralUtility::isAllowedAbsPath ($ absoluteFileName )
135
- && GeneralUtility::makeInstance (FileNameValidator::class)->isValid ($ absoluteFileName )
136
- && !str_starts_with ($ absoluteFileName , Environment::getLegacyConfigPath ());
137
- }
157
+ $ fileAccessAllowed = GeneralUtility::isAllowedAbsPath ($ absoluteFileName )
158
+ && GeneralUtility::makeInstance (FileNameValidator::class)->isValid ($ absoluteFileName )
159
+ && !str_starts_with ($ absoluteFileName , Environment::getLegacyConfigPath ());
138
160
if (!$ fileAccessAllowed ) {
139
161
throw new \Exception ('The requested file was not allowed to be accessed through Jump URL. The path or file is not allowed. ' , 1294585194 );
140
162
}
@@ -157,7 +179,7 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio
157
179
protected function isLocationDataValid (string $ locationData ): bool
158
180
{
159
181
$ isValidLocationData = false ;
160
- list ( $ pageUid , $ table , $ recordUid) = explode (': ' , $ locationData );
182
+ [ $ pageUid , $ table , $ recordUid] = explode (': ' , $ locationData );
161
183
$ pageRepository = $ this ->getTypoScriptFrontendController ()->sys_page ;
162
184
if (empty ($ table ) || $ pageRepository ->checkRecord ($ table , $ recordUid , true )) {
163
185
// This check means that a record is checked only if the locationData has a value for a
0 commit comments