本文介绍了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):

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

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

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

08-12 09:51