internetpixels/csrf-protection
Composer 安装命令:
composer require internetpixels/csrf-protection
包简介
Protect your web app from malicious requests by using CSRF protection tokens in links and forms
README 文档
README
Protect your web app from malicious requests by using CSRF protection tokens in links and forms. This CSRF protection library does not use sessions, files, memory storage or databases.
Basic examples
In the examples below you'll find the 3 most important methods:
TokenManager::create();TokenManager::createHtmlField();TokenManager::validate();
The full namespace is InternetPixels\CSRFProtection\TokenManager.
Setup the TokenManager
You have to set some settings for a secure TokenManager. Please overwrite the salt by your own one.
<?php TokenManager::setSalt('P*17OJznMttaR#Zzwi4YhAY!H7hPGUCd', 'ERGirehgr4893ur43tjrg98rut98ueowifj'); TokenManager::setUserId(7); TokenManager::setSessionToken('session_token');
Create a safe form
The TokenManager can improve the security
<form action="/your/page" method="post">
<?= TokenManager::createHtmlField('my_form') ?>
</form>
Create a safe link
When a user wants to delete an item in your application, you want to be sure that the request is valid. Create a token and add it in the link to your delete page.
<a href="/posts/delete/1?token=<?= TokenManager::create('delete_post') ?>">Delete Post</a>
In the delete action you want to validate the token with the TokenManager::validate() method.
Validate the user input
Once a user is posting the form data to your server(s), you'll first need to validate the given token. By default, the field name used is _token.
<?php if( filter_has_var(INPUT_POST, '_token') ) { if( TokenManager::validate('my_form', filter_input(INPUT_POST, '_token')) ) { // valid token } else { // invalid token } }
internetpixels/csrf-protection 适用场景与选型建议
internetpixels/csrf-protection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.18k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 internetpixels/csrf-protection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 internetpixels/csrf-protection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-06-12