Helpers\CSRF
Helpers\CSRF
CSRF Protection
The CSRF helper is used to protect post request from cross site request forgeries. For more information on CSRF see https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29_Prevention_Cheat_Sheet
To use place at the top of controller like:<
namespace Controllers;
use Core\Controller;
use Helpers\Csrf;
use Helpers\Session;
class Pet extends Controller
{
    private $model;
    public function __construct()
    {
        parent::__construct();
        $this->model = new \Models\PetModel();
    }
In your add or edit method create the token. If you use separate methods to open an edit view and a different method to update, create it in the edit method like:
function edit()
{
    $id = filter_input(INPUT_GET, 'id'); //suggested way....
    $data['csrfToken'] = Csrf::makeToken('edit');
    $data['row'] = $this->model->getPet($id);
    View::renderTemplate('header', $data);
    View::render('pet/edit', $data, $error);
    View::renderTemplate('footer', $data);
}
Before the submit button in same view, place this hidden field:
<input type="hidden" name="token" value="<?php echo $data['csrfToken']; ?>" />
In the controller and at the top of the method that processes the form, update here is only an example, place:
function update()
{
    if (isset($_POST['submit'])) { // or the name/value you assign to button.
       if (!Csrf::isTokenValid('edit')) {
            Url::redirect('admin/login'); // Or to a url you choose.......
        }
        $id = $_POST['id'];
        $petname = $_POST['petname'];
        // other processing code
Helpers\CSRF的更多相关文章
- Config
		
Config Config App Auth Cache Database Languages Mail Modules Routing Session Config Settings for the ...
 - ajax中加上AntiForgeryToken防止CSRF攻击
		
经常看到在项目中ajax post数据到服务器不加防伪标记,造成CSRF攻击 在Asp.net Mvc里加入防伪标记很简单在表单中加入Html.AntiForgeryToken()即可. Html.A ...
 - 记得ajax中要带上AntiForgeryToken防止CSRF攻击
		
经常看到在项目中ajax post数据到服务器不加防伪标记,造成CSRF攻击 在Asp.net Mvc里加入防伪标记很简单在表单中加入Html.AntiForgeryToken()即可. Html.A ...
 - 切记ajax中要带上AntiForgeryToken防止CSRF攻击
		
在程序项目中经常看到ajax post数据到服务器没有加上防伪标记,导致CSRF被攻击,下面小编通过本篇文章给大家介绍ajax中要带上AntiForgeryToken防止CSRF攻击,感兴趣的朋友一起 ...
 - ASP.NET Core MVC – Form Tag Helpers
		
ASP.NET Core Tag Helpers系列目录 ASP.NET Core MVC Tag Helpers 介绍 ASP.NET Core MVC – Caching Tag Helpers ...
 - .NET MVC CSRF/XSRF 漏洞
		
最近我跟一个漏洞还有一群阿三干起来了…… 背景: 我的客户是一个世界知名的药企,最近这个客户上台了一位阿三管理者,这个货上线第一个事儿就是要把现有的软件供应商重新洗牌一遍.由于我们的客户关系维护的非常 ...
 - Preventing CSRF With Ajax
		
https://stackoverflow.com/a/24394578/3782855 You don't need the ValidationHttpRequestWrapper solutio ...
 - CSRF in asp.net mvc and ap.net core
		
如果在方法上添加了[ValidateAntiForgeryToken],没处理好 请求没有带参数 2019-09-17 14:02:45,142 ERROR [36]: System.Web.Mvc. ...
 - 保护ASP.NET 应用免受 CSRF 攻击
		
CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSRF/ ...
 
随机推荐
- 如何卸载eclipse中的ADT
			
卸载ADT的方法,方法如下: 1.选择 Help > Install New Software: 2.在"Details" 面板中, 点击"What is alre ...
 - MVC 5 的 EF6 Code First 入门
			
英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with Entity Framework 6 Code First using MVC 5 系列 ...
 - Python中,如何初始化不同的变量类型为空值
			
参考文章 Python中,如何初始化不同的变量类型为空值 常见的数字,字符,很简单,不多解释. 列表List的其值是[x,y,z]的形式 字典Dictionary的值是{x:a, y:b, z:c} ...
 - Clear All of Them I(HDU 3920状压dp)
			
题意:给有2*n个敌人的位置,枪在(0,0)位置,一次能消灭两个敌人,耗费能量为枪到一个敌人,由这个敌人再到另个敌人的的距离和,求消灭所有敌人最小耗费能量. 分析:一次枚举状态的两位即可 #inclu ...
 - Testlink & Redmine组合拳演练
			
环境:Ubuntu 14.04LTS 一.部署testlink 查看已安装软件: dpkg -l *apache* (apache2.4.7) dpkg -l *php* (未安装) dpkg -l ...
 - .NET在WebForm里实现类似WinForm里面TrackBar控件的效果(AJAX Control Toolkit的使用)
			
WinForm 里面有一个 TrackBar 控件,表示一个标准的 Windows 跟踪条,是类似于 ScrollBar 控件的可滚动控件.用这个控件可以实现很多可以实时调整的功能,比如最常见的音量调 ...
 - BZOJ 1079 [SCOI2008]着色方案
			
http://www.lydsy.com/JudgeOnline/problem.php?id=1079 思路:如果把每种油漆看成一种状态,O(5^15)不行 DP[a][b][c][d][e][f] ...
 - 2016"百度之星" - 初赛(Astar Round2B)  1006	中位数计数
			
思路:统计当前数左边比它小|大 i个人,相应右边就应该是比它大|小i个人 l数组表示左边i个人的方案 r表示右边i个人的方案 数组下标不可能是负数所以要加n //#pragma comment(lin ...
 - 了解常见的 Azure 灾难
			
以下内容涵盖多种不同类型的灾难情况.数据中心故障不是应用程序范围内发生故障的唯一原因.设计不良或管理错误也会导致中断.请在恢复计划的设计和测试阶段设想可能导致故障的原因,这样做很重要.一个好的计划可充 ...
 - Linq to Sql 总生成 where ID is null 的解决办法
			
using (Entities com = new Entities()){ com.Configuration.UseDatabaseNullSemantics = true; } EF+M ...