url.php 1.6 KB

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