我正在尝试使用 security 组件才能避免CSRF攻击,如果我使用FormHelper以使用Postlink创建票证,就像这样,它会失败:

<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $user['User']['id']),  array('class' => 'button mini'), __('Are you sure?', $user['User']['id'])); ?>
.

我不确定这是可能的,还是cakephp只允许使用formhelper的create()和end()方法来允许此功能。

cakephp文档只说是是强制性地使用FormHelper但它没有更多地指定更多。

有帮助吗?

解决方案

当您启用了安全组件并且您使用Formhelper方法来满足所有表单,您不必担心此功能。您也不必配置任何内容。它在框中工作。

for csrf,您可以使用以下选项:

property SecurityComponent::$csrfCheck
Whether to use CSRF protected forms. Set to false to disable CSRF protection on forms.

property SecurityComponent::$csrfExpires
The duration from when a CSRF token is created that it will expire on. Each form/page request will generate a new token that can only be submitted once unless it expires. Can be any value compatible with strtotime(). The default is +30 minutes.

property SecurityComponent::$csrfUseOnce
Controls whether or not CSRF tokens are use and burn. Set to false to not generate new tokens on each request. One token will be reused until it expires. This reduces the chances of users getting invalid requests because of token consumption. It has the side effect of making CSRF less secure, as tokens are reusable.
.

如果您有一切,您应该在表单的HTML中看到CSRF令牌。您可以设置您喜欢的任何其他选项,但它会为您提供框中的几乎工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top