Skip to content

Commit d760a31

Browse files
committed
Added: not_contains matching type.
1 parent aa2e7b9 commit d760a31

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/Processor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ public function matchParameterValue($match, $value)
345345
return @stripos($value, $matchValue) !== false;
346346
}
347347

348+
// If a scalar does not contain a value.
349+
if ($matchType == 'not_contains' && is_scalar($value)) {
350+
return @stripos($value, $matchValue) === false;
351+
}
352+
348353
// If a string matches a regular expression.
349354
if ($matchType == 'regex' && is_string($matchValue) && is_scalar($value)) {
350355
return @preg_match($matchValue, @urldecode($value)) === 1;

tests/FirewallTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function testRules()
264264
);
265265
$this->assertFalse($this->processor->launch(false));
266266
$this->alterPayload();
267-
//post.user.role.type*
267+
268268
// Determine if a POST parameter (using wildcard) contains a certain character.
269269
$this->setUpFirewallProcessor([$this->rules[18]]);
270270
$this->alterPayload(
@@ -297,5 +297,24 @@ public function testRules()
297297
);
298298
$this->assertFalse($this->processor->launch(false));
299299
$this->alterPayload();
300+
301+
// Determine if a POST parameter does not contain a substring.
302+
$this->setUpFirewallProcessor([$this->rules[19]]);
303+
$this->alterPayload(
304+
['POST' => [
305+
'what' => 'myteststring'
306+
]]
307+
);
308+
$this->assertTrue($this->processor->launch(false));
309+
$this->alterPayload();
310+
311+
$this->setUpFirewallProcessor([$this->rules[19]]);
312+
$this->alterPayload(
313+
['POST' => [
314+
'what' => 'myvalidstring'
315+
]]
316+
);
317+
$this->assertFalse($this->processor->launch(false));
318+
$this->alterPayload();
300319
}
301320
}

tests/data/Rules.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,13 @@
150150
"cat":"TEST",
151151
"type":"BLOCK",
152152
"type_params":null
153+
},
154+
{
155+
"id":20,
156+
"title":"Determine if a POST parameter does not contain a substring.",
157+
"rules":[{"parameter":"post.what","match":{"type":"not_contains","value":"test"}}],
158+
"cat":"TEST",
159+
"type":"BLOCK",
160+
"type_params":null
153161
}
154162
]

0 commit comments

Comments
 (0)