CakePHP and CSRF

*爱你&永不变心* 提交于 2019-12-24 14:43:19

问题


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.


回答1:


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

public $components = array('Security');

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




回答2:


you can also import the Sanitze lib for extra strong security

http://book.cakephp.org/view/153/Data-Sanitization

App::import('Sanitize');
$badString = ";:<script><html><   // >@@#";
echo Sanitize::paranoid($badString);
// output: scripthtml
echo Sanitize::paranoid($badString, array(' ', '@'));
// output: scripthtml    @@


来源:https://stackoverflow.com/questions/1584420/cakephp-and-csrf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!