【问题标题】:how to make more secure backend and urls with zend?如何使用 zend 制作更安全的后端和 url?
【发布时间】:2014-04-17 14:33:19
【问题描述】:

我正在尝试用 Zend 做一个后端,我想知道是否有任何方法可以使它更安全,有什么特殊的框架可以使用吗?我读到我可以使用:Is there something like Acegi for PHP?

这有多安全?我以前使用过spring security,它总是很好用,有没有类似在zend上工作的东西?这些选项可以吗?

我也查了magento,比如url是这样的

index/key/8555b140ead18e6c004037e5c82d6478/

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

谢谢。

【问题讨论】:

    标签: php security magento zend-framework


    【解决方案1】:

    该密钥的生成取决于您正在访问的路由以及每次重新启动会话时都会更改的随机字符串。
    因此,对于每次登录,您都会获得不同的会话密钥。
    这种方法的缺点是您不能给其他人一个管理员网址并告诉他“嘿!看这里”,因为他们的会话密钥不同。

    如果你想检查这个功能是如何实现的,请看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');
    }
    

    【讨论】:

      猜你喜欢
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 2013-03-30
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 2013-03-01
      相关资源
      最近更新 更多