8 private $quotes =
array();
10 private $action =
"filter";
11 private $doLog =
false;
14 private $variables =
null;
17 private $searches =
null;
19 private $quotedSearches =
null;
29 $this->
setAction(COption::GetOptionString(
"security",
"filter_action"));
38 $this->
setLog(COption::GetOptionString(
"security",
"filter_log"));
47 if (CSecuritySystemInformation::isCliMode())
53 if (!preg_match(
'#</script#',
$content))
71 if(!$this->variables->isEmpty())
73 $this->searches = $this->variables->getSearchValues();
74 $this->quotedSearches = $this->variables->getQuoteSearchValues();
98 "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" # match double quoted string
100 \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' # match single quoted string
105 $this->quotes =
array();
106 return preg_replace_callback($regexp,
array($this,
"pushQuote"), $string);
109 return preg_replace($regexp,
'', $string);
117 $this->action = $action;
125 if(is_string($log) && $log ==
"Y")
131 $this->doLog =
false;
143 if(defined(
"ANTIVIRUS_CREATE_TRACE"))
156 $cache_id = md5($var_name.
'|'.
$str);
157 $fn =
$_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/cache/virus.db/".$cache_id.
".flt";
158 if(!file_exists($fn))
161 $f = fopen($fn,
"wb");
163 fwrite(
$f, $var_name.
": ".
$str);
164 fwrite(
$f,
"\n------------\n".$script);
165 fwrite(
$f,
"\n------------------------------\n\$_SERVER:\n");
167 fwrite(
$f,
$k.
" = ".$v.
"\n");
170 @chmod($fn, BX_FILE_PERMISSIONS);
180 $this->quotes[] = $quote[0];
191 foreach($searches as
$i => $search)
193 $pos = strpos($string, $search[
"value"]);
196 $prevChar = substr($string, $pos - 1, 1);
197 $isFound = ($prevChar !==
'\\');
198 if ($isFound && preg_match(
"/^[a-zA-Z_]/", $search[
"value"]))
200 $isFound = preg_match(
"/^[a-zA-Z_]/", $prevChar) <= 0;
216 $search = $this->
findInArray($body, $this->quotedSearches);
217 if ($search !==
null)
219 return $this->quotedSearches[$search];
221 else if (!empty($this->searches))
224 $search = $this->
findInArray($bodyWithoutQuotes, $this->searches);
225 if ($search !==
null)
227 return $this->searches[$search];
247 if($this->action !==
"none")
249 $body = self::SCRIPT_MARK;
262 if(preg_match(
'#\btype="text/html"#', $strs[1]))
265 if(trim($strs[2]) ===
"")
268 return $strs[1].$this->getFilteredScriptBody($strs[2]).$strs[3];
277 $stringLen = strlen($string) * 2;
278 Ini::adjustPcreBacktrackLimit($stringLen);
280 return preg_replace_callback(
"/(<script[^>]*>)(.*?)(<\\/script[^>]*>)/is",
array($this,
"getFilteredScript"), $string);
289 if(!is_string($value))
291 if(mb_strlen($value) <= 2)
293 if(preg_match(
"/^(?P<quot>[\"']?)[^`,;+\-*\/\{\}\[\]\(\)&\\|=\\\\]*(?P=quot)\$/D", $value))
295 if(preg_match(
"/^[,0-9_-]*\$/D", $value))
297 if(preg_match(
"/^[0-9 \n\r\t\\[\\]]*\$/D", $value))
300 $this->variables->addVariable(
$name, $value);
309 if(!is_array($array))
312 foreach($array as
$key => $value)
314 $variableName = sprintf(
'%s[%s]',
$name,
$key);
315 if (is_array($value))
static Check($siteId, $uri)
logVariable($name, $value, $sourceScript)
getFilteredScriptBody($body)
removeQuotedStrings($string, $isSaveQuotes=true)
__construct($options=array())
CreateTrace($var_name, $str, $script)
addVariable($name, $value)
static OnEndBufferContent(&$content)
findInArray($string, $searches)
extractVariablesFromArray($name, $array)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
if(empty($signedUserToken)) $key