url.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. use PhpMyAdmin\Core;
  9. use PhpMyAdmin\Sanitize;
  10. use PhpMyAdmin\Response;
  11. /**
  12. * Gets core libraries and defines some variables
  13. */
  14. define('PMA_MINIMUM_COMMON', true);
  15. require_once './libraries/common.inc.php';
  16. // Only output the http headers
  17. $response = Response::getInstance();
  18. $response->getHeader()->sendHttpHeaders();
  19. $response->disable();
  20. if (! Core::isValid($_GET['url'])
  21. || ! preg_match('/^https:\/\/[^\n\r]*$/', $_GET['url'])
  22. || ! Core::isAllowedDomain($_GET['url'])
  23. ) {
  24. Core::sendHeaderLocation('./');
  25. } else {
  26. // JavaScript redirection is necessary. Because if header() is used
  27. // then web browser sometimes does not change the HTTP_REFERER
  28. // field and so with old URL as Referer, token also goes to
  29. // external site.
  30. echo "<script type='text/javascript'>
  31. window.onload=function(){
  32. window.location='" , Sanitize::escapeJsString($_GET['url']) , "';
  33. }
  34. </script>";
  35. // Display redirecting msg on screen.
  36. // Do not display the value of $_GET['url'] to avoid showing injected content
  37. echo __('Taking you to the target site.');
  38. }
  39. die();