osynapsy/csrf
最新稳定版本:1.0
Composer 安装命令:
composer require osynapsy/csrf
包简介
Osynapsy CSRF protection package providing simple nonce + token generation for secure forms and actions.
关键字:
README 文档
README
A lightweight and simple CSRF protection package for Osynapsy forms and actions.
Provides a stateless, HMAC-based token system to secure sensitive POST operations.
Features
- Generate CSRF tokens (
nonce+token) for forms. - Easy integration with Osynapsy
Formcomponents. - Optional check in actions extending
AbstractAction. - Minimal and explicit: only enable CSRF where necessary.
- No session overhead, fully stateless.
Installation
Install via Composer:
composer require osynapsy/csrf
Usage
Adding CSRF fields to a form
use Osynapsy\Csrf\FormCsrf; $form = new \MyProject\Form\UserEditForm(); \FormCsrf::apply($form, $_ENV['CSRF_SECRET']);
This will add two hidden fields to your form:
- csrf_nonce
- csrf_token
Checking CSRF in an action
Extend your action from Osynapsy\Csrf\Action\AbstractAction:
public function execute() { $this->checkCsrf(); // Validates the CSRF token and nonce // Your action logic here }
The check will throw an exception if the CSRF token is missing or invalid.
Security Notes
Only enable CSRF on forms that perform sensitive POST operations. Use HTTPS and set secure cookies for sessions. Keep SECRET_KEY secret and unique per project. The package is stateless, so no server-side session storage is required.
Classes
Osynapsy\Csrf\Token – Generates and verifies CSRF tokens. Osynapsy\Csrf\FormCsrf – Helper to apply CSRF fields to a form. Osynapsy\Csrf\Action\AbstractAction – Base action with checkCsrf() method.
License
MIT licence
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-14