X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Fsecurity_functions.php;h=363bca731cd0feae1a4f11ed7a076d092c890b41;hb=8ba389b59f6d41f88752cae896143135e575f34a;hp=79599e4558dd6ace5280466af69a3b894f3ac18d;hpb=b5912168d72ae511eb623c3d92540c82d31b93c5;p=mailer.git diff --git a/inc/libs/security_functions.php b/inc/libs/security_functions.php index 79599e4558..363bca731c 100644 --- a/inc/libs/security_functions.php +++ b/inc/libs/security_functions.php @@ -32,8 +32,7 @@ ************************************************************************/ // Some security stuff... -if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) -{ +if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php"; require($INC); } @@ -42,7 +41,7 @@ if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) * Function to secure input strings * * @param $str The unsecured string - * @return $str A (hopefully) secured string against HTML and other things + * @return $str A (hopefully) secured string against XSS and other bad things */ function secureString ($str) { $str = trim(strip_tags($str)); @@ -57,35 +56,29 @@ if (defined('__SECURITY')) return; global $FATAL; $FATAL = array(); -// Runtime quoting is off now... -set_magic_quotes_runtime(false); - -// Unregister all global variables because of vultures and surpress failed attemps -@import_request_variables(''); - -// Error reporting level -@error_reporting(E_ALL | E_STRICT); +// Runtime/GPC quoting is off now... +@set_magic_quotes_runtime(false); +@ini_set('magic_quotes_gpc', false); // This may not work on some systems // Check if important arrays are found and define them if missing -if (!isset($_SERVER)) -{ +if (!isset($_SERVER)) { global $_SERVER; $_SERVER = $GLOBALS['_SERVER']; } -if (!isset($_GET)) -{ + +if (!isset($_GET)) { global $_GET; $_GET = $GLOBALS['_GET']; } -if (!isset($_POST)) -{ + +if (!isset($_POST)) { global $_POST; $_POST = $GLOBALS['_POST']; } -if (!isset($_SESSION)) -{ - global $_SESSION; - $_SESSION = $GLOBALS['_COOKIE']; + +if (!isset($_COOKIE)) { + global $_COOKIE; + $_COOKIE = $GLOBALS['_COOKIE']; } // Include IP-Filter here @@ -95,14 +88,14 @@ if (!isset($_SESSION)) global $SEC_CHARS, $URL_CHARS; $SEC_CHARS = array( // The chars we are looking for... - 'from' => array("{", "}", "/", ".", "'", "$", "(", ")", "{--", "--}", "%", ";", "[", "]", ":", "--"), + 'from' => array("{", "}", "/", ".", "'", "$", "(", ")", '{--', '--}', "%", ";", "[", "]", ":", "--"), // ... and we will replace to. 'to' => array( "{OPEN_ANCHOR2}", "{CLOSE_ANCHOR2}", "{SLASH}", "{DOT}", - "{QUOT}", + '{QUOT}', "{DOLLAR}", "{OPEN_ANCHOR}", "{CLOSE_ANCHOR}", @@ -130,18 +123,13 @@ $URL_CHARS = array( // Overworked security part: if (is_array($_GET)) { - foreach ($_GET as $seckey=>$secvalue) - { - if (is_array($secvalue)) - { + foreach ($_GET as $seckey => $secvalue) { + if (is_array($secvalue)) { // Throw arrays away... unset($_GET[$seckey]); - } - else - { + } else { // Only variables are allowed (non-array) but we secure them all! - foreach ($SEC_CHARS['from'] as $key=>$char) - { + foreach ($SEC_CHARS['from'] as $key => $char) { // Pass all through $_GET[$seckey] = str_replace($char , $SEC_CHARS['to'][$key], $_GET[$seckey]); } @@ -152,16 +140,12 @@ if (is_array($_GET)) { } } -if (basename($_SERVER['PHP_SELF']) != "install.php") -{ +if (basename($_SERVER['PHP_SELF']) != "install.php") { // And POST data - foreach ($_POST as $seckey=>$secvalue) - { - if (!is_array($secvalue)) - { + foreach ($_POST as $seckey => $secvalue) { + if (!is_array($secvalue)) { // Only variables are allowed (non-array) to be secured... - foreach ($SEC_CHARS['from'] as $key=>$char) - { + foreach ($SEC_CHARS['from'] as $key => $char) { // Pass all through $_POST[$seckey] = str_replace($char , $SEC_CHARS['to'][$key], $_POST[$seckey]); } @@ -172,47 +156,35 @@ if (basename($_SERVER['PHP_SELF']) != "install.php") } // ... and finally cookies - foreach ($_SESSION as $seckey=>$secvalue) - { - if (is_array($secvalue)) - { + foreach ($_COOKIE as $seckey => $secvalue) { + if (is_array($secvalue)) { // Throw arrays away... - unset($_SESSION[$seckey]); - } - else - { + unset($_COOKIE[$seckey]); + } else { // Only variables are allowed (non-array) but we secure them all! - foreach ($SEC_CHARS['from'] as $key=>$char) - { + foreach ($SEC_CHARS['from'] as $key => $char) { // Pass all through - $_SESSION[$seckey] = str_replace($char , $SEC_CHARS['to'][$key], $_SESSION[$seckey]); + $_COOKIE[$seckey] = str_replace($char , $SEC_CHARS['to'][$key], $_COOKIE[$seckey]); } // Strip all other out - $_SESSION[$seckey] = strip_tags($_SESSION[$seckey]); + $_COOKIE[$seckey] = strip_tags($_COOKIE[$seckey]); } } } // Activate caching or transparent compressing when it is not already done -if (!defined('_OB_CACHING')) -{ - if (phpversion() >= '4.0.4pl1' && (strstr(getenv('HTTP_USER_AGENT'),'compatible') || (strstr(getenv('HTTP_USER_AGENT'), "Mozilla")))) - { - if ((extension_loaded('zlib')) && (function_exists('ob_start'))) - { +if (!defined('_OB_CACHING')) { + if (phpversion() >= '4.0.4pl1' && (strstr(getenv('HTTP_USER_AGENT'),'compatible') || (strstr(getenv('HTTP_USER_AGENT'), "Mozilla")))) { + if ((extension_loaded('zlib')) && (function_exists('ob_start'))) { // Start caching define('_OB_CACHING', "on"); ob_start(); - } - else - { + } else { // Extension not loaded or required function is missing define('_OB_CACHING', "404"); } - } - else - { + } else { // Old PHP version define('_OB_CACHING', "old"); } @@ -226,8 +198,7 @@ $SELF_DIR = dirname($_SERVER['PHP_SELF']); $SELF_FILE = basename($_SERVER['PHP_SELF']); // Check for a .php inside the $SELF_DIR... -while (ereg(".php", $SELF_DIR)) -{ +while (ereg(".php", $SELF_DIR)) { // Correct the dirname $SELF_DIR = substr($SELF_DIR, 0, (strpos($SELF_DIR, ".php") + 4)); // Rewrite filename...