Translated using Weblate (Persian)
[phpmyadmin.git] / url.php
blobf8785a4cfb07453f886fd56aa43f4ad14ab00309
1 <?php
2 /**
3 * URL redirector to avoid leaking Referer with some sensitive information.
4 */
5 declare(strict_types=1);
7 use PhpMyAdmin\Core;
8 use PhpMyAdmin\DatabaseInterface;
9 use PhpMyAdmin\Response;
10 use PhpMyAdmin\Sanitize;
12 if (! defined('ROOT_PATH')) {
13 // phpcs:disable PSR1.Files.SideEffects
14 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
15 // phpcs:enable
18 global $containerBuilder, $dbi;
20 // phpcs:disable PSR1.Files.SideEffects
21 define('PMA_MINIMUM_COMMON', true);
22 // phpcs:enable
24 require_once ROOT_PATH . 'libraries/common.inc.php';
26 // Load database service because services.php is not available here
27 $dbi = DatabaseInterface::load();
28 $containerBuilder->set(DatabaseInterface::class, $dbi);
30 // Only output the http headers
31 $response = Response::getInstance();
32 $response->getHeader()->sendHttpHeaders();
33 $response->disable();
35 if (! Core::isValid($_GET['url'])
36 || ! preg_match('/^https:\/\/[^\n\r]*$/', $_GET['url'])
37 || ! Core::isAllowedDomain($_GET['url'])
38 ) {
39 Core::sendHeaderLocation('./');
40 } else {
41 // JavaScript redirection is necessary. Because if header() is used
42 // then web browser sometimes does not change the HTTP_REFERER
43 // field and so with old URL as Referer, token also goes to
44 // external site.
45 $template = $containerBuilder->get('template');
46 echo $template->render('javascript/redirect', [
47 'url' => Sanitize::escapeJsString($_GET['url']),
48 ]);
49 // Display redirecting msg on screen.
50 // Do not display the value of $_GET['url'] to avoid showing injected content
51 echo __('Taking you to the target site.');
53 die;