ali1/brute-force-shield
Composer 安装命令:
composer require ali1/brute-force-shield
包简介
A tool to enable powerful, easy to use, Brute Force Protection.
关键字:
README 文档
README
Features
- Use for IP address-based protection but can be used with other unique identifiers
- Does not count re-attempts with same challenge details (e.g. if a user tries the same username/password combination a few times)
- Designed to use with any data store (file, mysql, cache library) and any framework
- Can block multiple attempts at the same username earlier than the normal limit (to give users a chance to enter the correct username if they have been trying with the wrong one)
Requirements
- Composer
- PHP 7.2 or higher
- Any data store to persist the User History data between requests
Installation
composer require ali1/brute-force-shield
Configuration
When applying protection, a Ali1\BruteForceShield\Configuration object can be provided.
$configuration = new Configuration(); $configuration->setTimeWindow(600) ->setTotalAttemptsLimit(10);
| Configuration method | Details |
|---|---|
setTimeWindow(int $timeWindow) |
Time in seconds until Brute Force Protection resets (default: 300) |
setTotalAttemptsLimit(int $totalAttempts) |
Number of attempts before blocking further challenges (default: 8) |
addUnencryptedKey(string $keyName) |
By default, all entered user data is irreversibly hashed when prepared for storage. Use addUnencryptedKey for each key for which you want the data to be stored plaintext to aid debugging or security logging (i.e. usernames) |
setStricterLimitOnKey(string $keyName, int $limitAttempts) |
This optional method is useful in id/password type scenarios. You can configure the shield to further limit the number of attempts if using the same id/username repeatedly (i.e. use setStricterLimitOnKey('username', 7) and setTotalAttemptsLimit(10) to allow 7 attempts for a user, and then another 3 if user tries a different username) |
Usage
As you will need your own architecture to store data and log blocked events, it is recommended to create a method, function, component or middleware to use this library.
Check out this CakePHP component as an example of a helper method you could use.
However if you want to use it directly, here is an example:
public function login() { // prior to actually verifying data $bruteConfig = new Configuration(); $bruteConfig->setTotalAttemptsLimit(10) ->setStricterLimitOnKey('username', 7) ->addUnencryptedKey('username'); $cacheKey = 'BruteforceData.login.' . str_replace(':', '.', $_SERVER['REMOTE_ADDR']); $userDataRaw = Cache::read($cacheKey); // replace with your way of retrieving stored user data $shield = new BruteForceShield(); $userData = $userDataRaw ? json_decode($userDataRaw, true) : null; $userData = $shield->validate($userData, $_POST, $bruteConfig); Cache::write($cacheKey, json_encode($userData)); // replace with your way of storing user data if (!$shield->isValidated()) { Log::alert( "Bruteforce blocked\nIP: {$this->getController()->getRequest()->getEnv('REMOTE_ADDR')}\n", json_encode($userData) ); // replace with your own method of logging throw new TooManyAttemptsException(); // replace with your way of error handling and stopping execution } // now you can process the login attempt in the normal way }
ali1/brute-force-shield 适用场景与选型建议
ali1/brute-force-shield 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.03k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「bruteforce」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ali1/brute-force-shield 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ali1/brute-force-shield 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ali1/brute-force-shield 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library for limiting both brute-force attempts and ordinary requests, using leaky/token bucket algorithm, based on Redis
Symfony bundle that integrates gentle-force library for limiting both brute-force attempts and ordinary requests, using leaky/token bucket algorithm, based on Redis
Protects TYPO3 frontend authentication (e.g. fe_login) against brute force attacks.
Provide a way to secure accesses to all routes of an symfony application.
CakePHP Plugin for Brute Force Protection
It's a barebone security class written on PHP
统计信息
- 总下载量: 10.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-21