diff --git a/objects/security.php b/objects/security.php index afc3fc8a5..389894fd0 100644 --- a/objects/security.php +++ b/objects/security.php @@ -1,135 +1,92 @@ $value) { + $_FILES[$key]['name'] = preg_replace('/[^a-z0-9.,()+& #-]/i', '', cleanString($_FILES[$key]['name'])); } } -if (!empty($_POST['base64Url'])) { - if (!filter_var(base64_decode($_POST['base64Url']), FILTER_VALIDATE_URL)) { - _error_log('base64Url attack ' . json_encode($_SERVER), AVideoLog::$SECURITY); - exit; - } -} +$scanVars = array('GET', 'POST', 'REQUEST'); -foreach ($filterURL as $key => $value) { - if (!empty($_GET[$value])) { - if (!filter_var($_GET[$value], FILTER_VALIDATE_URL) || !preg_match("/^http.*/i", $_GET[$value])) { - //_error_log($value.' attack ' . json_encode($_SERVER), AVideoLog::$SECURITY); - unset($_GET[$value]); - } else { - $_GET[$value] = str_replace(array("'",'"',"<",">"), array("","","",""), $_GET[$value]); +foreach ($scanVars as $value) { + eval('$scanThis = &$_' . $value.';'); + if (!empty($scanThis['base64Url'])) { + if (!filter_var(base64_decode($scanThis['base64Url']), FILTER_VALIDATE_URL)) { + _error_log('base64Url attack ' . json_encode($_SERVER), AVideoLog::$SECURITY); + exit; } } - if (!empty($_POST[$value])) { - if (!filter_var($_POST[$value], FILTER_VALIDATE_URL) || !preg_match("/^http.*/i", $_POST[$value])) { - _error_log($value.' attack ' . json_encode($_SERVER), AVideoLog::$SECURITY); - unset($_POST[$value]); - } else { - $_POST[$value] = str_replace(array("'",'"',"<",">"), array("","","",""), $_POST[$value]); - } - } -} -if (!empty($_FILES)) { - foreach ($_FILES as $key=>$value) { - $_FILES[$key]['name'] = preg_replace('/[^a-z0-9.,()+& #-]/i', '', cleanString($_FILES[$key]['name'])); - } -} - -foreach ($securityRemoveNonChars as $value) { - if (!empty($_POST[$value])) { - if (is_string($_POST[$value])) { - $_POST[$value] = str_replace('/[^a-z0-9./]/i', '', trim($_POST[$value])); - } elseif (is_array($_POST[$value])) { - foreach ($_POST[$value] as $key => $value2) { - if (is_string($_POST[$value][$key])) { - $_POST[$value][$key] = str_replace('/[^a-z0-9./]/i', '', trim($_POST[$value][$key])); - } + foreach ($filterURL as $key => $value) { + if (!empty($scanThis[$value])) { + if (!filter_var($scanThis[$value], FILTER_VALIDATE_URL) || !preg_match("/^http.*/i", $scanThis[$value])) { + //_error_log($value.' attack ' . json_encode($_SERVER), AVideoLog::$SECURITY); + unset($scanThis[$value]); + } else { + $scanThis[$value] = str_replace(array("'", '"', "<", ">"), array("", "", "", ""), $scanThis[$value]); } } } - if (!empty($_GET[$value])) { - if (is_string($_GET[$value])) { - $_GET[$value] = str_replace('/[^a-z0-9./]/i', '', trim($_GET[$value])); - } elseif (is_array($_GET[$value])) { - foreach ($_GET[$value] as $key => $value2) { - if (is_string($_GET[$value][$key])) { - $_GET[$value][$key] = str_replace('/[^a-z0-9./]/i', '', trim($_GET[$value][$key])); + + + foreach ($securityRemoveNonChars as $value) { + if (!empty($scanThis[$value])) { + if (is_string($scanThis[$value])) { + $scanThis[$value] = str_replace('/[^a-z0-9./]/i', '', trim($scanThis[$value])); + } elseif (is_array($scanThis[$value])) { + foreach ($scanThis[$value] as $key => $value2) { + if (is_string($scanThis[$value][$key])) { + $scanThis[$value][$key] = str_replace('/[^a-z0-9./]/i', '', trim($scanThis[$value][$key])); + } } } } } -} -foreach ($securityRemoveSingleQuotes as $value) { - if (!empty($_POST[$value])) { - if (is_string($_POST[$value])) { - $_POST[$value] = str_replace("'", "", trim($_POST[$value])); - } elseif (is_array($_POST[$value])) { - foreach ($_POST[$value] as $key => $value2) { - if (is_string($_POST[$value][$key])) { - $_POST[$value][$key] = str_replace("'", "", trim($_POST[$value][$key])); + + foreach ($securityRemoveSingleQuotes as $value) { + if (!empty($scanThis[$value])) { + if (is_string($scanThis[$value])) { + $scanThis[$value] = str_replace("'", "", trim($scanThis[$value])); + } elseif (is_array($scanThis[$value])) { + foreach ($scanThis[$value] as $key => $value2) { + if (is_string($scanThis[$value][$key])) { + $scanThis[$value][$key] = str_replace("'", "", trim($scanThis[$value][$key])); + } } } } } - if (!empty($_GET[$value])) { - if (is_string($_GET[$value])) { - $_GET[$value] = str_replace("'", "", trim($_GET[$value])); - } elseif (is_array($_GET[$value])) { - foreach ($_GET[$value] as $key => $value2) { - if (is_string($_GET[$value][$key])) { - $_GET[$value][$key] = str_replace("'", "", trim($_GET[$value][$key])); - } + + + foreach ($securityFilterInt as $value) { + if (!empty($scanThis[$value])) { + if (strtolower($scanThis[$value]) === "true") { + $scanThis[$value] = 1; + } else { + $scanThis[$value] = intval($scanThis[$value]); } } } -} -foreach ($securityFilterInt as $value) { - if (!empty($_POST[$value])) { - if (strtolower($_POST[$value])==="true") { - $_POST[$value] = 1; - } else { - $_POST[$value] = intval($_POST[$value]); - } - } - if (!empty($_GET[$value])) { - if (strtolower($_GET[$value])==="true") { - $_GET[$value] = 1; - } else { - $_GET[$value] = intval($_GET[$value]); + foreach ($securityFilter as $value) { + if (!empty($scanThis[$value])) { + $scanThis[$value] = str_replace(array("'", '"', """, "'", "%23", "%5c", "#"), array('', '', '', '', '', '', ''), xss_esc($scanThis[$value])); } } -} - -foreach ($securityFilter as $value) { - if (!empty($_POST[$value])) { - $_POST[$value] = str_replace(array("'", '"', """, "'"), array('', '', '', ''), xss_esc($_POST[$value])); - } - if (!empty($_GET[$value])) { - $_GET[$value] = str_replace(array("'", '"', """, "'"), array('', '', '', ''), xss_esc($_GET[$value])); - } -} -if (!empty($_GET['sort']) && is_array($_GET['sort'])) { - foreach ($_GET['sort'] as $key => $value) { - $_GET['sort'][xss_esc($key)] = strcasecmp($value, "ASC") === 0 ? "ASC" : "DESC"; - } -} -if (!empty($_POST['sort']) && is_array($_POST['sort'])) { - foreach ($_POST['sort'] as $key => $value) { - $_POST['sort'][xss_esc($key)] = strcasecmp($value, "ASC") === 0 ? "ASC" : "DESC"; + if (!empty($scanThis['sort']) && is_array($scanThis['sort'])) { + foreach ($scanThis['sort'] as $key => $value) { + $scanThis['sort'][xss_esc($key)] = strcasecmp($value, "ASC") === 0 ? "ASC" : "DESC"; + } } -} +} \ No newline at end of file