Allow setting trusted_proxies using CIDR notation

This commit is contained in:
Dmitrii Chekaliuk 2013-03-08 22:55:36 +02:00 committed by Fabien Potencier
parent ddc9e3892f
commit 811434f988
2 changed files with 17 additions and 1 deletions

View File

@ -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()

View File

@ -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')),
);
}