在DDD中实施CSRF保护

时间:2014-07-31 16:58:21

标签: php domain-driven-design csrf

我正在使用PHP和MVC模式。

我得到了功能,但(我猜)它不在DDD范例内。

目前我的注册控制器中有以下内容:

public function index()
{
    $this->session->setParameter('token', CryptoCharGen::alnum());

    return $this->view->index();
}

public function submit()
{
    $token = array(
        'post'    => $this->request->getParameter('token'),
        'session' => $this->session->getParameter('token')
    );

    // Check if the submission is valid before proceeding (CSRF protection).
    if ($token['post'] === $token['session'] && $token['session']) {
        // other logic
    }

    return $this->view->submit();
}

如何在域驱动的设计模式中实施CSRF保护?

如果有人能为我提供一个明确的(伪)代码示例,那将会有所帮助。

1 个答案:

答案 0 :(得分:0)

DDD与应用程序级安全性无关,为什么不看一下如何获得应用程序安全性。

HTTP只是一个端口,不属于您的域模型。

看看这个,看看客户端用户界面的位置以及域模型的位置。

紫色外圈是你关注的地方,也不在DDD的范围之内

enter image description here