1313use PhpMyAdmin \Http \Handler \QueueRequestHandler ;
1414use PhpMyAdmin \Http \Response ;
1515use PhpMyAdmin \Http \ServerRequest ;
16- use PhpMyAdmin \Identifiers \DatabaseName ;
17- use PhpMyAdmin \Identifiers \TableName ;
1816use PhpMyAdmin \Middleware \Authentication ;
1917use PhpMyAdmin \Middleware \ConfigErrorAndPermissionChecking ;
2018use PhpMyAdmin \Middleware \ConfigLoading ;
5351use PhpMyAdmin \Routing \Routing ;
5452use Psr \Http \Message \ResponseInterface ;
5553use Psr \Http \Message \ServerRequestInterface ;
56- use Symfony \Component \DependencyInjection \ContainerInterface ;
5754use Throwable ;
5855
59- use function __ ;
60- use function function_exists ;
61- use function hash_equals ;
62- use function is_array ;
63- use function is_scalar ;
64- use function session_id ;
6556use function sprintf ;
66- use function strlen ;
67- use function trigger_error ;
68-
69- use const E_USER_ERROR ;
7057
7158class Application
7259{
@@ -93,7 +80,7 @@ public function run(bool $isSetupPage = false): void
9380 $ requestHandler = new QueueRequestHandler (new ApplicationHandler ($ this ));
9481 $ requestHandler ->add (new ErrorHandling ($ this ->errorHandler ));
9582 $ requestHandler ->add (new OutputBuffering ());
96- $ requestHandler ->add (new PhpExtensionsChecking ($ this , $ this ->template , $ this ->responseFactory ));
83+ $ requestHandler ->add (new PhpExtensionsChecking ($ this ->template , $ this ->responseFactory ));
9784 $ requestHandler ->add (new ServerConfigurationChecking ($ this ->template , $ this ->responseFactory ));
9885 $ requestHandler ->add (new PhpSettingsConfiguration ());
9986 $ requestHandler ->add (new RouteParsing ());
@@ -107,8 +94,8 @@ public function run(bool $isSetupPage = false): void
10794 ));
10895 $ requestHandler ->add (new EncryptedQueryParamsHandling ());
10996 $ requestHandler ->add (new UrlParamsSetting ($ this ->config ));
110- $ requestHandler ->add (new TokenRequestParamChecking ($ this ));
111- $ requestHandler ->add (new DatabaseAndTableSetting ($ this ));
97+ $ requestHandler ->add (new TokenRequestParamChecking ());
98+ $ requestHandler ->add (new DatabaseAndTableSetting ());
11299 $ requestHandler ->add (new SqlQueryGlobalSetting ());
113100 $ requestHandler ->add (new LanguageLoading ());
114101 $ requestHandler ->add (new ConfigErrorAndPermissionChecking (
@@ -162,119 +149,4 @@ public function handle(ServerRequest $request): Response|null
162149 $ this ->responseFactory ,
163150 );
164151 }
165-
166- /**
167- * Checks that required PHP extensions are there.
168- */
169- public function checkRequiredPhpExtensions (): void
170- {
171- /**
172- * Warning about mbstring.
173- */
174- if (! function_exists ('mb_detect_encoding ' )) {
175- Core::warnMissingExtension ('mbstring ' );
176- }
177-
178- /**
179- * We really need this one!
180- */
181- if (! function_exists ('preg_replace ' )) {
182- Core::warnMissingExtension ('pcre ' , true );
183- }
184-
185- /**
186- * JSON is required in several places.
187- */
188- if (! function_exists ('json_encode ' )) {
189- Core::warnMissingExtension ('json ' , true );
190- }
191-
192- /**
193- * ctype is required for Twig.
194- */
195- if (! function_exists ('ctype_alpha ' )) {
196- Core::warnMissingExtension ('ctype ' , true );
197- }
198-
199- if (! function_exists ('mysqli_connect ' )) {
200- $ moreInfo = sprintf (__ ('See %sour documentation%s for more information. ' ), '[doc@faqmysql] ' , '[/doc] ' );
201- Core::warnMissingExtension ('mysqli ' , true , $ moreInfo );
202- }
203-
204- if (! function_exists ('session_name ' )) {
205- Core::warnMissingExtension ('session ' , true );
206- }
207-
208- /**
209- * hash is required for cookie authentication.
210- */
211- if (function_exists ('hash_hmac ' )) {
212- return ;
213- }
214-
215- Core::warnMissingExtension ('hash ' , true );
216- }
217-
218- /**
219- * Check whether user supplied token is valid, if not remove any possibly
220- * dangerous stuff from request.
221- *
222- * Check for token mismatch only if the Request method is POST.
223- * GET Requests would never have token and therefore checking
224- * mis-match does not make sense.
225- */
226- public function checkTokenRequestParam (): void
227- {
228- $ GLOBALS ['token_mismatch ' ] = true ;
229- $ GLOBALS ['token_provided ' ] = false ;
230-
231- if (($ _SERVER ['REQUEST_METHOD ' ] ?? 'GET ' ) !== 'POST ' ) {
232- return ;
233- }
234-
235- if (isset ($ _POST ['token ' ]) && is_scalar ($ _POST ['token ' ]) && strlen ((string ) $ _POST ['token ' ]) > 0 ) {
236- $ GLOBALS ['token_provided ' ] = true ;
237- $ GLOBALS ['token_mismatch ' ] = ! @hash_equals ($ _SESSION [' PMA_token ' ], (string ) $ _POST ['token ' ]);
238- }
239-
240- if (! $ GLOBALS ['token_mismatch ' ]) {
241- return ;
242- }
243-
244- // Warn in case the mismatch is result of failed setting of session cookie
245- if (isset ($ _POST ['set_session ' ]) && $ _POST ['set_session ' ] !== session_id ()) {
246- trigger_error (
247- __ (
248- 'Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin. ' ,
249- ),
250- E_USER_ERROR ,
251- );
252- }
253-
254- /**
255- * We don't allow any POST operation parameters if the token is mismatched
256- * or is not provided.
257- */
258- $ allowList = ['ajax_request ' ];
259- Sanitize::removeRequestVars ($ allowList );
260- }
261-
262- public function setDatabaseAndTableFromRequest (ContainerInterface $ container , ServerRequest $ request ): void
263- {
264- $ GLOBALS ['urlParams ' ] ??= null ;
265-
266- $ db = DatabaseName::tryFrom ($ request ->getParam ('db ' ));
267- $ table = TableName::tryFrom ($ request ->getParam ('table ' ));
268-
269- $ GLOBALS ['db ' ] = $ db ?->getName() ?? '' ;
270- $ GLOBALS ['table ' ] = $ table ?->getName() ?? '' ;
271-
272- if (! is_array ($ GLOBALS ['urlParams ' ])) {
273- $ GLOBALS ['urlParams ' ] = [];
274- }
275-
276- $ GLOBALS ['urlParams ' ]['db ' ] = $ GLOBALS ['db ' ];
277- $ GLOBALS ['urlParams ' ]['table ' ] = $ GLOBALS ['table ' ];
278- $ container ->setParameter ('url_params ' , $ GLOBALS ['urlParams ' ]);
279- }
280152}
0 commit comments