url.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * URL redirector to avoid leaking Referer with some sensitive information.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. declare(strict_types=1);
  9. use PhpMyAdmin\Core;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Sanitize;
  12. use PhpMyAdmin\DatabaseInterface;
  13. if (! defined('ROOT_PATH')) {
  14. define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
  15. }
  16. /**
  17. * Gets core libraries and defines some variables
  18. */
  19. define('PMA_MINIMUM_COMMON', true);
  20. require_once ROOT_PATH . 'libraries/common.inc.php';
  21. // Load database service because services.yaml is not available here
  22. $containerBuilder->set(DatabaseInterface::class, DatabaseInterface::load());
  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. echo "<script type='text/javascript'>
  38. window.onload=function(){
  39. window.location='" , Sanitize::escapeJsString($_GET['url']) , "';
  40. }
  41. </script>";
  42. // Display redirecting msg on screen.
  43. // Do not display the value of $_GET['url'] to avoid showing injected content
  44. echo __('Taking you to the target site.');
  45. }
  46. die();