Skip to content

Commit

Permalink
security fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcrypto committed Jun 14, 2021
1 parent c50087d commit 634017d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Validation/Rules/RequiredIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class RequiredIf
*/
public function __construct($condition)
{
$this->condition = $condition;
if(!is_string($condition) && (is_bool($condition) || is_callable($condition))) {
$this->condition = $condition;
} else {
throw new InvalidArgumentException("Condition type must be 'callable' or 'bool'.");
}
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/Validation/ValidationRequiredIfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,30 @@ public function testItClousureReturnsFormatsAStringVersionOfTheRule()

$this->assertSame('', (string) $rule);
}

public function testItOnlyCallableAndBooleanAreAcceptableArgumentsOfTheRule()
{
$rule = new RequiredIf(false);

$rule = new RequiredIf(true);

$this->expectException(InvalidArgumentException::class);

$rule = new RequiredIf('phpinfo');

$rule = new RequiredIf(12.3);

$rule = new RequiredIf(new stdClass());
}

public function testItReturnedRuleIsNotSerializable()
{
$this->expectException(Exception::class);

$rule = serialize(new RequiredIf(function () {
return true;
}));

$rule = serialize(new RequiredIf());
}
}

0 comments on commit 634017d

Please sign in to comment.