我最近部署了Symfony 1.3.6網站。我選擇在服務器上保留frontend_dev.php,以便在絕對需要時在本地機器上進行調試。如何防止調試工具欄出現在產品環境中
我修改frontend_dev.php這樣的:
<?php
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
// 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')))
{
//in case something screwy happens ...
try
{
// die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
sfContext::createInstance($configuration)->getController()->forward('security', 'error404');
exit();
}
catch(Exception $e)
{
//if we got here, all bets are off anyway, just go away ....
exit();
}
}
sfContext::createInstance($configuration)->dispatch();
我所做的一切是爲了將請求定向到一個404錯誤頁面。然而,我注意到當我輸入http://www.mywebsite.com/frontend_dev.php/some_valid_url.html
我被引導到404頁面(正如我想的那樣) - 但顯示調試工具欄 - 顯然這是一個安全風險。從非本地計算機訪問dev控制器時禁用工具欄的最佳方法是什麼?
我想在error404動作中放入檢查代碼,然後在需要時禁用調試工具欄,但我不確定這是否是最符合symfonic的做法。
在這種情況下最好的做法是什麼?
就我個人而言,我剛剛在代碼中將我的IP地址添加到數組中,以允許臨時訪問frontend_dev控制器,然後將其刪除。 – Tom 2010-11-03 12:33:26