1 | <?php |
||
5 | class JavaScript extends Resources |
||
|
|||
6 | { |
||
7 | private $ANTI_XSS_STYLE = 'anti-xss::STYLE'; |
||
8 | |||
9 | 6 | public function removeDisallowedJavascript($str) |
|
76 | |||
77 | 6 | private function jsLinkRemovalCallback(array $match) |
|
81 | |||
82 | 6 | private function jsRemovalCallback(array $match, $search) |
|
83 | { |
||
84 | 6 | if (!$match[0]) { |
|
85 | return ''; |
||
86 | } |
||
87 | |||
88 | // init |
||
89 | 6 | $match_style_matched = false; |
|
90 | 6 | $match_style = []; |
|
91 | |||
92 | // hack for style attributes v1 |
||
93 | 6 | if ($search === 'href' && stripos($match[0], 'style') !== false) { |
|
94 | 2 | preg_match('/style=".*?"/i', $match[0], $match_style); |
|
95 | 2 | $match_style_matched = (count($match_style) > 0); |
|
96 | 2 | if ($match_style_matched) { |
|
97 | 2 | $match[0] = str_replace($match_style[0], $this->ANTI_XSS_STYLE, $match[0]); |
|
98 | } |
||
99 | } |
||
100 | |||
101 | 6 | $replacer = $this->_filter_attributes(str_replace(['<', '>'], '', $match[1])); |
|
102 | |||
103 | // filter for "(.*)" but only in the "$search"-attribute |
||
104 | 6 | if (stripos($replacer, $search) !== false) { |
|
105 | 6 | $pattern = '#' . $search . '=(?<wrapper>(?:\'|\047)|(?:"|\042)).*(?:\g{wrapper})#isU'; |
|
106 | 6 | $matchInner = []; |
|
107 | 6 | $foundSomethingBad = false; |
|
108 | 6 | preg_match($pattern, $match[1], $matchInner); |
|
109 | 6 | if (count($matchInner) > 0 && preg_match('#(?:\(.*([^\)]*?)(?:\)))#s', $matchInner[0])) { |
|
110 | 6 | $foundSomethingBad = true; |
|
111 | |||
112 | 6 | $replacer = (string)preg_replace($pattern, $search . '="' . $this->_replacement . '"', $replacer); |
|
113 | } |
||
114 | |||
115 | 6 | if (!$foundSomethingBad) { |
|
116 | // filter for javascript |
||
117 | 6 | $pattern = '#' . $search . '=.*(?:javascript:|view-source:|livescript:|wscript:|vbscript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|d\s*a\s*t\s*a\s*:)#ius'; |
|
118 | 6 | $matchInner = []; |
|
119 | 6 | preg_match($pattern, $match[1], $matchInner); |
|
120 | 6 | if (count($matchInner) > 0) { |
|
121 | 2 | $replacer = (string)preg_replace($pattern, $search . '="' . $this->_replacement . '"', $replacer); |
|
122 | } |
||
123 | } |
||
124 | } |
||
125 | |||
126 | 6 | $return = str_ireplace($match[1], $replacer, (string)$match[0]); |
|
127 | |||
128 | // hack for style attributes v2 |
||
129 | 6 | if ($match_style_matched && $search === 'href') { |
|
130 | 2 | $return = str_replace($this->ANTI_XSS_STYLE, $match_style[0], $return); |
|
131 | } |
||
132 | |||
133 | 6 | return $return; |
|
134 | } |
||
135 | |||
136 | 6 | private function jsSrcRemovalCallback(array $match) |
|
140 | |||
141 | 6 | public function naughtyJavascript($str) |
|
150 | |||
151 | } |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.