Skip to content

Commit 8945778

Browse files
committed
Changed: more validations to the rule matching.
1 parent 097d446 commit 8945778

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/Processor.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function launch($mustExit = true)
145145
continue;
146146
}
147147

148-
// Execute the firewall rule.
148+
// Transform rule object to array, then execute the firewall rule.
149149
$rule_hit = $this->executeFirewall(json_decode(json_encode($rule->rules), true));
150150

151151
// If the payload did not match the rule, continue.
@@ -285,15 +285,15 @@ public function matchParameterValue($match, $value)
285285
$matchValue = isset($match['value']) ? $match['value'] : null;
286286

287287
// Perform a match depending on the given match type.
288-
if ($matchType == 'equals' && is_scalar($value)) {
288+
if ($matchType == 'equals' && is_scalar($value) && is_scalar($matchValue)) {
289289
return $matchValue == $value;
290290
}
291291

292-
if ($matchType == 'bigger_than' && is_scalar($value)) {
292+
if ($matchType == 'bigger_than' && is_scalar($value) && is_scalar($matchValue)) {
293293
return $value > $matchValue;
294294
}
295295

296-
if ($matchType == 'less_than' && is_scalar($value)) {
296+
if ($matchType == 'less_than' && is_scalar($value) && is_scalar($matchValue)) {
297297
return $value < $matchValue;
298298
}
299299

@@ -321,19 +321,19 @@ public function matchParameterValue($match, $value)
321321
return @preg_match($matchValue, @urldecode($value)) === 1;
322322
}
323323

324-
if ($matchType == 'current_user_cannot' && function_exists('current_user_can')) {
324+
if ($matchType == 'current_user_cannot' && is_scalar($matchValue) && function_exists('current_user_can')) {
325325
return @!current_user_can($matchValue);
326326
}
327327

328-
if ($matchType == 'in_array' && !is_array($value)) {
328+
if ($matchType == 'in_array' && !is_array($value) && is_array($matchValue)) {
329329
return @in_array($value, $matchValue);
330330
}
331331

332-
if ($matchType == 'not_in_array' && !is_array($value)) {
332+
if ($matchType == 'not_in_array' && !is_array($value) && is_array($matchValue)) {
333333
return @!in_array($value, $matchValue);
334334
}
335335

336-
if ($matchType == 'array_in_array' && is_array($value)) {
336+
if ($matchType == 'array_in_array' && is_array($value) && is_array($matchValue)) {
337337
return @array_intersect($value, $matchValue);
338338
}
339339

0 commit comments

Comments
 (0)