CakePHP和CSRF [英] CakePHP and CSRF

查看:140
本文介绍了CakePHP和CSRF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚接触CakePHP,想知道如何保护我的表单免于跨站点请求伪造,即在表单中添加一个随机数。我已经在配置文件中设置了盐。

I'm new to CakePHP and am wondering how to protect my forms from Cross Site Request Forgery, ie adding a nonce to the forms. I've set the salt in the config file.

推荐答案

您必须将Security组件添加到$ components数组控制器:

You have to add the Security component to the $components array of your controller(s):


public $ components = array('Security');

public $components = array('Security');

当您使用Form帮助器创建表单时,CakePHP会自动向您的表单添加一个随机数。

CakePHP will then automatically add a nonce to your form when you use the Form helper to create your forms.

这篇关于CakePHP和CSRF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆