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/ ...
随机推荐
- ubuntu12.04 安装 chrome
1.下载deb包 2. sudo apt-get remove google-chrome-stable sudo dpkg -i google-chrome-stable_current_amd64 ...
- Android_1_渐变背景色
首先创建一个渐变背景色文件drawable-mdpi/bg_color.xml <?xml version="1.0" encoding="utf-8"? ...
- Magento 切换成中文后没有数据信息解决办法
进入后台的, 选择CMS---pages, 看到这个么? 如果这里显示的不是所有商店界面的话, 就点击进去,然后选择所有商店界面: 如下所示: 再点击保存就可以了.
- Bzoj 4556: [Tjoi2016&Heoi2016]字符串
4556: [Tjoi2016&Heoi2016]字符串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 177 Solved: 92[Sub ...
- IntelliJ远程调试教程
概述 对于分布式系统的调试不知道大家有什么好的方法.对于我来说,在知道远程调试这个方法之前就是在代码中打各种log,然后重新部署,上线,调试,这样比较费时.今天咱们来了解了解Java远程调试这个牛逼的 ...
- Java条件语句 switch case
不得不说的几点小秘密: 1. switch 后面小括号中表达式的值必须是整型或字符型 2. case 后面的值可以是常量数值,如 1.2:也可以是一个常量表达式,如 2+2 :但不能是变量或带有变量的 ...
- Android最新锁屏病毒分析及解锁
一.情况简介 从去年开始PC端的敲诈者类病毒在不断的爆发,今年年初的时候手机上也开始出现了敲诈者之类的病毒,对这类病毒很无语也是趋势,因为很多时候病毒的产生是和金钱利益相关的.前天去吾爱破解论坛病 ...
- 实现windows和linux互传文件
http://www.cnblogs.com/ylan2009/archive/2012/01/12/2321126.html 尝试从windows xp向ubuntu11.10传文件 ubuntu使 ...
- mysql数据库全局只读和会话只读问题解析
对于系统的发布是经常有的事情,有些时候需要隔绝外界对数据库的更改但是还要求可以读取数据,对于mss sql 这个就是很简单,直接属性—>选项—>只读 ,但是对于mysql这是不同的,今天仔 ...
- 补丁安装命令(WUSA)
wusa windows6.1-kb2716513-x64.msu /quiet /norestart msxml4-kb2758694-enu.exe /quiet /norestart 安装.ms ...