Allow setting trusted_proxies using CIDR notation
This commit is contained in:
parent
ddc9e3892f
commit
811434f988
@ -46,7 +46,21 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->prototype('scalar')
|
||||
->validate()
|
||||
->ifTrue(function($v) { return !empty($v) && !filter_var($v, FILTER_VALIDATE_IP); })
|
||||
->ifTrue(function($v) {
|
||||
if (empty($v)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false !== strpos($v, '/')) {
|
||||
list($v, $mask) = explode('/', $v, 2);
|
||||
|
||||
if (strcmp($mask, (int) $mask) || $mask < 1 || $mask > (false !== strpos($v, ':') ? 128 : 32)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return !filter_var($v, FILTER_VALIDATE_IP);
|
||||
})
|
||||
->thenInvalid('Invalid proxy IP "%s"')
|
||||
->end()
|
||||
->end()
|
||||
|
@ -51,6 +51,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
array(null, array()),
|
||||
array(false, array()),
|
||||
array(array(), array()),
|
||||
array(array('10.0.0.0/8'), array('10.0.0.0/8')),
|
||||
array(array('::ffff:0:0/96'), array('::ffff:0:0/96')),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user