PluginProbe
The WP Remote WordPress Plugin / 6.36
The WP Remote WordPress Plugin v6.36
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / protect / fw / rule / functions / string.php

string.php in The WP Remote WordPress Plugin 6.36, at protect/fw/rule/functions/string.php

335 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped
3 if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit;
4
5 if (!trait_exists('WPRProtectFWRuleStringFunc_V636')) :
6 trait WPRProtectFWRuleStringFunc_V636 {
7 private function _rf_isNumeric() {
8 $args = $this->processRuleFunctionParams(
9 'isNumeric',
10 func_num_args(),
11 func_get_args(),
12 1
13 );
14 $value = $args[0];
15
16 return (WPRHelper::safePregMatch('/^\d+$/', $value));
17 }
18
19 private function _rf_isRegularWord() {
20 $args = $this->processRuleFunctionParams(
21 'isRegularWord',
22 func_num_args(),
23 func_get_args(),
24 1
25 );
26 $value = $args[0];
27
28 return (WPRHelper::safePregMatch('/^\w+$/', $value));
29 }
30
31 private function _rf_isSpecialWord() {
32 $args = $this->processRuleFunctionParams(
33 'isSpecialWord',
34 func_num_args(),
35 func_get_args(),
36 1
37 );
38 $value = $args[0];
39
40 return (WPRHelper::safePregMatch('/^\S+$/', $value));
41 }
42
43 private function _rf_isRegularSentence() {
44 $args = $this->processRuleFunctionParams(
45 'isRegularSentence',
46 func_num_args(),
47 func_get_args(),
48 1
49 );
50 $value = $args[0];
51
52 return (WPRHelper::safePregMatch('/^[\w\s]+$/', $value));
53 }
54
55 private function _rf_isSpecialCharsSentence() {
56 $args = $this->processRuleFunctionParams(
57 'isSpecialCharsSentence',
58 func_num_args(),
59 func_get_args(),
60 1
61 );
62 $value = $args[0];
63
64 return (WPRHelper::safePregMatch('/^[\w\W]+$/', $value));
65 }
66
67 private function _rf_isLink() {
68 $args = $this->processRuleFunctionParams(
69 'isLink',
70 func_num_args(),
71 func_get_args(),
72 1
73 );
74 $value = $args[0];
75
76 return (WPRHelper::safePregMatch('/^(http|ftp)s?:\/\/\S+$/i', $value));
77 }
78
79 private function _rf_isIpv4() {
80 $args = $this->processRuleFunctionParams(
81 'isIpv4',
82 func_num_args(),
83 func_get_args(),
84 1
85 );
86 $value = $args[0];
87
88 return (WPRHelper::safePregMatch('/^\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b$/x', $value));
89 }
90
91 private function _rf_isEmbededIpv4() {
92 $args = $this->processRuleFunctionParams(
93 'isEmbededIpv4',
94 func_num_args(),
95 func_get_args(),
96 1
97 );
98 $value = $args[0];
99
100 return (WPRHelper::safePregMatch('/\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/x', $value));
101 }
102
103 private function _rf_isIpv6() {
104 $args = $this->processRuleFunctionParams(
105 'isIpv6',
106 func_num_args(),
107 func_get_args(),
108 1
109 );
110 $value = $args[0];
111
112 return (WPRHelper::safePregMatch('/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/x', $value));
113 }
114
115 private function _rf_isEmbededIpv6() {
116 $args = $this->processRuleFunctionParams(
117 'isEmbededIpv6',
118 func_num_args(),
119 func_get_args(),
120 1
121 );
122 $value = $args[0];
123
124 return (WPRHelper::safePregMatch('/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/x', $value));
125 }
126
127 private function _rf_isEmail() {
128 $args = $this->processRuleFunctionParams(
129 'isEmail',
130 func_num_args(),
131 func_get_args(),
132 1
133 );
134 $value = $args[0];
135
136 return (WPRHelper::safePregMatch('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/', $value));
137 }
138
139 private function _rf_isEmbededEmail($value) {
140 $args = $this->processRuleFunctionParams(
141 'isEmbededEmail',
142 func_num_args(),
143 func_get_args(),
144 1
145 );
146 $value = $args[0];
147
148 return (WPRHelper::safePregMatch('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}/', $value));
149 }
150
151 private function _rf_isEmbededLink() {
152 $args = $this->processRuleFunctionParams(
153 'isEmbededLink',
154 func_num_args(),
155 func_get_args(),
156 1
157 );
158 $value = $args[0];
159
160 return (WPRHelper::safePregMatch('/(http|ftp)s?:\/\/\S+$/i', $value));
161 }
162
163 private function _rf_isEmbededHtml() {
164 $args = $this->processRuleFunctionParams(
165 'isEmbededHtml',
166 func_num_args(),
167 func_get_args(),
168 1
169 );
170 $value = $args[0];
171
172 return (WPRHelper::safePregMatch('/<(html|head|title|base|link|meta|style|picture|source|img|iframe|embed|object|param|video|audio|track|map|area|form|label|input|button|select|datalist|optgroup|option|textarea|output|progress|meter|fieldset|legend|script|noscript|template|slot|canvas)/ix', $value));
173 }
174
175 private function _rf_isFile() {
176 $args = $this->processRuleFunctionParams(
177 'isFile',
178 func_num_args(),
179 func_get_args(),
180 1
181 );
182 $value = $args[0];
183
184 return (WPRHelper::safePregMatch('/\.(jpg|jpeg|png|gif|ico|pdf|doc|docx|ppt|pptx|pps|ppsx|odt|xls|zip|gzip|xlsx|psd|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2|php|html|phtml|js|css)/ix', $value));
185 }
186
187 private function _rf_isPathTraversal() {
188 $args = $this->processRuleFunctionParams(
189 'isPathTraversal',
190 func_num_args(),
191 func_get_args(),
192 1
193 );
194 $value = $args[0];
195
196 return (WPRHelper::safePregMatch('/(?:\.{2}[\/]+)/', $value));
197 }
198
199 private function _rf_isPhpEval() {
200 $args = $this->processRuleFunctionParams(
201 'isPhpEval',
202 func_num_args(),
203 func_get_args(),
204 1
205 );
206 $value = $args[0];
207
208 return (WPRHelper::safePregMatch('/\\b(?i:eval)\\s*\\(\\s*(?i:base64_decode|exec|file_get_contents|gzinflate|passthru|shell_exec|stripslashes|system)\\s*\\(/', $value));
209 }
210
211 private function _rf_isSubstring() {
212 $args = $this->processRuleFunctionParams(
213 'isSubstring',
214 func_num_args(),
215 func_get_args(),
216 2
217 );
218 $string = $args[0];
219 $substring = $args[1];
220
221 return strpos((string) $string, (string) $substring) !== false;
222 }
223
224 private function _rf_containsAnySubstring() {
225 $args = $this->processRuleFunctionParams(
226 'containsAnySubstring',
227 func_num_args(),
228 func_get_args(),
229 2
230 );
231 $string = $args[0];
232 $array_of_substrings = $args[1];
233
234 if (is_array($array_of_substrings)) {
235 foreach ($array_of_substrings as $i => $substring) {
236 if ($this->_rf_isSubstring($string, $substring)) {
237 return true;
238 }
239 }
240 } else {
241 throw new WPRProtectRuleError_V636(
242 $this->addExState("containsAnySubstring: Expects an array of substrings.")
243 );
244 }
245
246 return false;
247 }
248
249 private function _rf_concatString() {
250 $args = $this->processRuleFunctionParams(
251 'concatString',
252 func_num_args(),
253 func_get_args(),
254 2,
255 ['string', 'string']
256 );
257 $source_str = $args[0];
258 $str = $args[1];
259
260 return $source_str . $str;
261 }
262
263 private function _rf_strPos() {
264 $args = $this->processRuleFunctionParams(
265 'strPos',
266 func_num_args(),
267 func_get_args(),
268 2,
269 ['string', 'string']
270 );
271 $haystack = $args[0];
272 $needle = $args[1];
273 $offset = isset($args[2]) ? $args[2] : 0;
274
275 if (!is_int($offset)) {
276 throw new WPRProtectRuleError_V636(
277 $this->addExState("strPos: Offset should be an integer")
278 );
279 }
280
281 return strpos($haystack, $needle, $offset);
282 }
283
284 private function _rf_checkStringsForSubstringsPos() {
285 $args = $this->processRuleFunctionParams(
286 'checkStringsForSubstringsPos',
287 func_num_args(),
288 func_get_args(),
289 3,
290 ['array', 'array', 'integer']
291 );
292 $strings = $args[0];
293 $sub_strings = $args[1];
294 $pos = $args[2];
295
296 foreach ($strings as $string) {
297 foreach ($sub_strings as $sub_string) {
298 $position = $this->_rf_strPos($string, $sub_string);
299 if ($position === $pos) {
300 return true;
301 }
302 }
303 }
304
305 return false;
306 }
307
308 private function _rf_splitString() {
309 $args = $this->processRuleFunctionParams(
310 'splitString',
311 func_num_args(),
312 func_get_args(),
313 2,
314 ['string', 'string']
315 );
316 $separator = $args[0];
317 $str = $args[1];
318 $limit = isset($args[2]) ? $args[2] : PHP_INT_MAX;
319
320 if (empty($separator)) {
321 throw new WPRProtectRuleError_V636(
322 $this->addExState("splitString: Separator cannot be empty")
323 );
324 }
325
326 if (!is_int($limit)) {
327 throw new WPRProtectRuleError_V636(
328 $this->addExState("splitString: Limit should be an integer")
329 );
330 }
331
332 return explode($separator, $str, $limit);
333 }
334 }
335 endif;