Browse Source

Update front controllers, enable proxy trusting for packagist.org

Jordi Boggiano 12 years ago
parent
commit
13ed026454
2 changed files with 28 additions and 16 deletions
  1. 11 5
      web/app.php
  2. 17 11
      web/app_dev.php

+ 11 - 5
web/app.php

@@ -2,14 +2,20 @@
 
 ini_set('date.timezone', 'UTC');
 
-require_once __DIR__.'/../app/bootstrap.php.cache';
+use Symfony\Component\HttpFoundation\Request;
+
+$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
+
 require_once __DIR__.'/../app/AppKernel.php';
 require_once __DIR__.'/../app/AppCache.php';
 
-use Symfony\Component\HttpFoundation\Request;
-
 $kernel = new AppKernel('prod', false);
 $kernel->loadClassCache();
-// wrap the default AppKernel with the AppCache one
 $kernel = new AppCache($kernel);
-$kernel->handle(Request::createFromGlobals())->send();
+if ($_SERVER['HTTP_HOST'] === 'packagist.org') {
+    Request::trustProxyData();
+}
+$request = Request::createFromGlobals();
+$response = $kernel->handle($request);
+$response->send();
+$kernel->terminate($request, $response);

+ 17 - 11
web/app_dev.php

@@ -2,21 +2,27 @@
 
 ini_set('date.timezone', 'UTC');
 
-// this check prevents access to debug front controllers that are deployed by accident to production servers.
-// feel free to remove this, extend it, or make something more sophisticated.
-if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
-    '127.0.0.1',
-    '::1',
-))) {
+use Symfony\Component\HttpFoundation\Request;
+
+// This check prevents access to debug front controllers that are deployed by accident to production servers.
+// Feel free to remove this, extend it, or make something more sophisticated.
+if (isset($_SERVER['HTTP_CLIENT_IP'])
+    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
+    || !in_array(@$_SERVER['REMOTE_ADDR'], array(
+        '127.0.0.1',
+        '::1',
+    ))
+) {
     header('HTTP/1.0 403 Forbidden');
-    die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
+    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
 }
 
-require_once __DIR__.'/../app/bootstrap.php.cache';
+$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
 require_once __DIR__.'/../app/AppKernel.php';
 
-use Symfony\Component\HttpFoundation\Request;
-
 $kernel = new AppKernel('dev', true);
 $kernel->loadClassCache();
-$kernel->handle(Request::createFromGlobals())->send();
+$request = Request::createFromGlobals();
+$response = $kernel->handle($request);
+$response->send();
+$kernel->terminate($request, $response);