Skip to content

Commit 634017d

Browse files
committed
security fix
1 parent c50087d commit 634017d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Illuminate/Validation/Rules/RequiredIf.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class RequiredIf
1919
*/
2020
public function __construct($condition)
2121
{
22-
$this->condition = $condition;
22+
if(!is_string($condition) && (is_bool($condition) || is_callable($condition))) {
23+
$this->condition = $condition;
24+
} else {
25+
throw new InvalidArgumentException("Condition type must be 'callable' or 'bool'.");
26+
}
2327
}
2428

2529
/**

tests/Validation/ValidationRequiredIfTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,30 @@ public function testItClousureReturnsFormatsAStringVersionOfTheRule()
2929

3030
$this->assertSame('', (string) $rule);
3131
}
32+
33+
public function testItOnlyCallableAndBooleanAreAcceptableArgumentsOfTheRule()
34+
{
35+
$rule = new RequiredIf(false);
36+
37+
$rule = new RequiredIf(true);
38+
39+
$this->expectException(InvalidArgumentException::class);
40+
41+
$rule = new RequiredIf('phpinfo');
42+
43+
$rule = new RequiredIf(12.3);
44+
45+
$rule = new RequiredIf(new stdClass());
46+
}
47+
48+
public function testItReturnedRuleIsNotSerializable()
49+
{
50+
$this->expectException(Exception::class);
51+
52+
$rule = serialize(new RequiredIf(function () {
53+
return true;
54+
}));
55+
56+
$rule = serialize(new RequiredIf());
57+
}
3258
}

0 commit comments

Comments
 (0)