简体   繁体   English

Zend Framework1应用程序上的CSRF全局保护

[英]CSRF protection globally on Zend Framework1 application

I need to add CSRF protection on ZF1 project globally. 我需要在ZF1项目上全局添加CSRF保护。 I know how to add for single form but I have already created lots of form in the project. 我知道如何为单个表单添加内容,但是我已经在项目中创建了很多表单。 So to do it for each and every form is very tedious and very time consuming job. 因此,针对每种形式进行此操作非常繁琐且非常耗时。 I need a plug-in or any library for ZF1 that add a layer on top of every form element and receives post request with CSRF token on every form. 我需要ZF1的插件或任何库,它们在每个表单元素的顶部添加一个层,并在每个表单上接收带有CSRF令牌的后请求。 Any logic to implement this is highly appreciated. 高度赞赏任何实现此目的的逻辑。

只需使用您自己的CustomForm扩展Zend_Form并在init()函数中添加csrf字段创建即可。

This blog post explains how to add CSRF as an after thought. 这篇博客文章解释了如何添加CSRF。

Basically you need two things: 基本上,您需要两件事:

  1. JavaScript to catch ajax posts and form post events, where you inject a CSRF code into the form data before submit. 使用JavaScript捕获ajax帖子和表单发布事件,您可以在提交表单之前在表单数据中注入CSRF代码。
  2. A preDispatch plugin in Zend that checks the CSRF token on POST requests. Zend中的preDispatch插件,用于检查POST请求中的CSRF令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM