From e6bb156f48aea5227b060f9b2a31500f86398a67 Mon Sep 17 00:00:00 2001 From: Bart van den Burg Date: Tue, 11 Dec 2012 11:18:21 +0100 Subject: [PATCH 1/6] remove realpath call I'm trying to create an executable phar archive from a Symfony application, but when I run the phar, it fails to find any commands because of this php bug/feature: https://bugs.php.net/bug.php?id=52769 After this change, my archive works just like a normal app/console call --- src/Symfony/Component/HttpKernel/Bundle/Bundle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 494feabe58..3348456c54 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -172,7 +172,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface */ public function registerCommands(Application $application) { - if (!$dir = realpath($this->getPath().'/Command')) { + if (!is_dir($dir = $this->getPath().'/Command')) { return; } From a0e23910633a2761b3fdeee235ce2001aa9afc07 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Thu, 6 Dec 2012 13:06:01 +0100 Subject: [PATCH 2/6] [FrameworkBundle] used the new method for trusted proxies --- .../DependencyInjection/Configuration.php | 10 +++++++++- .../DependencyInjection/FrameworkExtension.php | 3 +++ src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index f32523c561..eab82121c0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -47,7 +47,15 @@ class Configuration implements ConfigurationInterface $rootNode ->children() ->scalarNode('charset')->end() - ->scalarNode('trust_proxy_headers')->defaultFalse()->end() + ->arrayNode('trusted_proxies') + ->prototype('scalar') + ->validate() + ->ifTrue(function($v) { return !filter_var($v, FILTER_VALIDATE_IP); }) + ->thenInvalid('Invalid proxy IP "%s"') + ->end() + ->end() + ->end() + ->scalarNode('trust_proxy_headers')->defaultFalse()->end() // @deprecated, to be removed in 2.3 ->scalarNode('secret')->isRequired()->end() ->scalarNode('ide')->defaultNull()->end() ->booleanNode('test')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 989991ad34..0a74063123 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -62,6 +62,9 @@ class FrameworkExtension extends Extension } $container->setParameter('kernel.secret', $config['secret']); + $container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']); + + // @deprecated, to be removed in 2.3 $container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']); if (!empty($config['test'])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 5f34b12ef8..06284b96a5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -37,8 +37,10 @@ class FrameworkBundle extends Bundle { public function boot() { - if ($this->container->getParameter('kernel.trust_proxy_headers')) { - Request::trustProxyData(); + if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) { + Request::setTrustedProxies($trustedProxies); + } elseif ($this->container->getParameter('kernel.trust_proxy_headers')) { + Request::trustProxyData(); // @deprecated, to be removed in 2.3 } } From 26b8b47221d87beed5a591ad412733b491c30fb8 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Tue, 11 Dec 2012 22:10:36 +0100 Subject: [PATCH 3/6] checked for a potentially missing key The 'function' key isn't always available in the trace. This was causing me a notice. --- src/Symfony/Component/HttpKernel/Exception/FlattenException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Exception/FlattenException.php b/src/Symfony/Component/HttpKernel/Exception/FlattenException.php index 50e83bd509..a9eecc3179 100644 --- a/src/Symfony/Component/HttpKernel/Exception/FlattenException.php +++ b/src/Symfony/Component/HttpKernel/Exception/FlattenException.php @@ -161,7 +161,7 @@ class FlattenException 'short_class' => $class, 'class' => isset($entry['class']) ? $entry['class'] : '', 'type' => isset($entry['type']) ? $entry['type'] : '', - 'function' => $entry['function'], + 'function' => isset($entry['function']) ? $entry['function'] : null, 'file' => isset($entry['file']) ? $entry['file'] : null, 'line' => isset($entry['line']) ? $entry['line'] : null, 'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : array(), From 773d818d6bdcdacd705d4d07a7291900e1a6e3d3 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Fri, 14 Dec 2012 11:45:40 +0100 Subject: [PATCH 4/6] [FrameworkBundle] Added a check on file mime type for CodeHelper::fileExcerpt() --- .../FrameworkBundle/Templating/Helper/CodeHelper.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index df8b0501a7..b075fb41c7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -143,6 +143,13 @@ class CodeHelper extends Helper public function fileExcerpt($file, $line) { if (is_readable($file)) { + if (extension_loaded('fileinfo')) { + $finfo = new \Finfo(); + if ('application/octet-stream' === $finfo->file($file, FILEINFO_MIME_TYPE)) { + return; + } + } + $code = highlight_file($file, true); // remove main code/span tags $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); From 555e777b0c45e710a19a0a55eb9a6c28bd2c18c5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves LEBECQ Date: Fri, 14 Dec 2012 11:26:52 +0100 Subject: [PATCH 5/6] [FrameworkBundle] Added tests for trusted_proxies configuration. --- .../DependencyInjection/ConfigurationTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000000..d6d7cf9a14 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; + +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration; +use Symfony\Component\Config\Definition\Processor; + +class ConfigurationTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTestConfigTreeData + */ + public function testConfigTree($options, $results) + { + $processor = new Processor(); + $configuration = new Configuration(array()); + $config = $processor->processConfiguration($configuration, array($options)); + + $this->assertEquals($results, $config); + } + + public function getTestConfigTreeData() + { + return array( + array(array('secret' => 's3cr3t'), array('secret' => 's3cr3t', 'trusted_proxies' => array(), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))), + ); + } + + /** + * @dataProvider getTestValidTrustedProxiesData + */ + public function testValidTrustedProxies($options, $results) + { + $processor = new Processor(); + $configuration = new Configuration(array()); + $config = $processor->processConfiguration($configuration, array($options)); + + $this->assertEquals($results, $config); + } + + public function getTestValidTrustedProxiesData() + { + return array( + array(array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))), + array(array('secret' => 's3cr3t', 'trusted_proxies' => array('::1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('::1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))), + array(array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1', '::1')), array('secret' => 's3cr3t', 'trusted_proxies' => array('127.0.0.1', '::1'), 'trust_proxy_headers' => false, 'ide' => NULL, 'annotations' => array('cache' => 'file', 'file_cache_dir' => '%kernel.cache_dir%/annotations', 'debug' => false))), + ); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException + */ + public function testInvalidTypeTrustedProxies() + { + $processor = new Processor(); + $configuration = new Configuration(array()); + $config = $processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => 'Not an IP address'))); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testInvalidValueTrustedProxies() + { + $processor = new Processor(); + $configuration = new Configuration(array()); + $config = $processor->processConfiguration($configuration, array(array('secret' => 's3cr3t', 'trusted_proxies' => array('Not an IP address')))); + } +} From d3f5f3a44f51d8255924d69dfaf8e753d3d51bf9 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Fri, 14 Dec 2012 12:28:34 +0100 Subject: [PATCH 6/6] Added comment --- .../Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index b075fb41c7..ef24fe8f69 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -145,6 +145,8 @@ class CodeHelper extends Helper if (is_readable($file)) { if (extension_loaded('fileinfo')) { $finfo = new \Finfo(); + + // Check if the file is an application/octet-stream (eg. Phar file) because hightlight_file cannot parse these files if ('application/octet-stream' === $finfo->file($file, FILEINFO_MIME_TYPE)) { return; }