Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MaliciousCode.php
Go to the documentation of this file.
1 <?php
10 
12 {
18  protected $_expressions = [
19  //comments, must be first
20  '/(\/\*.*\*\/)/Us',
21  //tabs
22  '/(\t)/',
23  //javasript prefix
24  '/(javascript\s*:)/Usi',
25  //import styles
26  '/(@import)/Usi',
27  //js in the style attribute
28  '/style=[^<]*((expression\s*?\([^<]*?\))|(behavior\s*:))[^<]*(?=\/*>)/Uis',
29  //js attributes
30  '/(ondblclick|onclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|'.
31  'onload|onunload|onerror)=[^<]*(?=\/*>)/Uis',
32  //tags
33  '/<\/?(script|meta|link|frame|iframe|object).*>/Uis',
34  //base64 usage
35  '/src=[^<]*base64[^<]*(?=\/*>)/Uis',
36  ];
37 
44  public function filter($value)
45  {
46  $replaced = 0;
47  do {
48  $value = preg_replace($this->_expressions, '', $value, -1, $replaced);
49  } while ($replaced !== 0);
50  return $value;
51  }
52 
59  public function addExpression($expression)
60  {
61  if (!in_array($expression, $this->_expressions)) {
62  $this->_expressions[] = $expression;
63  }
64  return $this;
65  }
66 
73  public function setExpressions(array $expressions)
74  {
75  $this->_expressions = $expressions;
76  return $this;
77  }
78 }
$expressions
Definition: side-menu.phtml:10
$value
Definition: gender.phtml:16