cleanup.lib.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Functions for cleanup of user input.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Removes all variables from request except whitelisted ones.
  13. *
  14. * @param string &$whitelist list of variables to allow
  15. *
  16. * @return void
  17. * @access public
  18. */
  19. function PMA_removeRequestVars(&$whitelist)
  20. {
  21. // do not check only $_REQUEST because it could have been overwritten
  22. // and use type casting because the variables could have become
  23. // strings
  24. $keys = array_keys(
  25. array_merge((array)$_REQUEST, (array)$_GET, (array)$_POST, (array)$_COOKIE)
  26. );
  27. foreach ($keys as $key) {
  28. if (! in_array($key, $whitelist)) {
  29. unset($_REQUEST[$key], $_GET[$key], $_POST[$key], $GLOBALS[$key]);
  30. } else {
  31. // allowed stuff could be compromised so escape it
  32. // we require it to be a string
  33. if (isset($_REQUEST[$key]) && ! is_string($_REQUEST[$key])) {
  34. unset($_REQUEST[$key]);
  35. }
  36. if (isset($_POST[$key]) && ! is_string($_POST[$key])) {
  37. unset($_POST[$key]);
  38. }
  39. if (isset($_COOKIE[$key]) && ! is_string($_COOKIE[$key])) {
  40. unset($_COOKIE[$key]);
  41. }
  42. if (isset($_GET[$key]) && ! is_string($_GET[$key])) {
  43. unset($_GET[$key]);
  44. }
  45. }
  46. }
  47. }
  48. ?>