如何使用zend制作更安全的后端和url



我正在尝试用Zend做一个后端,我想知道是否有任何方法可以让它更安全,使用任何特殊的框架?我读到我可以使用:PHP有类似Acegi的东西吗?

这有多安全?我以前使用过spring安全性,它总是很有效,有类似于zend的工作吗?这些选项可以吗?

我还检查了magento,例如,url就像这个

index/key/8555b140ead18e6c004037e5c82d6478/

那就是url,如果我想输入catalogo,等等,他们只更改密钥,而不是更改控制器名称的url,该密钥是出于安全原因的路由吗?还是由框架动态创建?(据我所知,他们使用Zend)。

谢谢。

该密钥是根据您正在访问的路由和每次重新启动会话时都会更改的随机字符串生成的
因此,每次登录都会获得不同的会话密钥
这种方法的缺点是,你不能给别人一个管理员url,然后告诉他"嘿!看这里",因为他们的会话密钥不同。

如果您想检查此功能是如何实现的,请查看Mage_Adminhtml_Model_Url::getUrl():中的以下代码

$_route = $this->getRouteName() ? $this->getRouteName() : '*';
$_controller = $this->getControllerName() ? $this->getControllerName() : $this->getDefaultControllerName();
$_action = $this->getActionName() ? $this->getActionName() : $this->getDefaultActionName();
if ($cacheSecretKey) {
    $secret = array(self::SECRET_KEY_PARAM_NAME => "${$_controller}/{$_action}$");
}
else {
   $secret = array(self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($_controller, $_action));
}

这是生成密钥的代码。深入getSecretKey方法,您将看到:

public function getSecretKey($controller = null, $action = null)
{
    $salt = Mage::getSingleton('core/session')->getFormKey();
    $p = explode('/', trim($this->getRequest()->getOriginalPathInfo(), '/'));
    if (!$controller) {
        $controller = !empty($p[1]) ? $p[1] : $this->getRequest()->getControllerName();
    }
    if (!$action) {
        $action = !empty($p[2]) ? $p[2] : $this->getRequest()->getActionName();
    }
    $secret = $controller . $action . $salt;
    return Mage::helper('core')->getHash($secret);
}

因此,密钥是根据控制器名称、操作名称和以这种方式生成的$salt Mage::getSingleton('core/session')->getFormKey(); 构建的哈希

getFormKey方法如下(每个会话一个值):

public function getFormKey()
{
    if (!$this->getData('_form_key')) {
        $this->setData('_form_key', Mage::helper('core')->getRandomString(16));
    }
    return $this->getData('_form_key');
}

最新更新