karster /
dev-master
2017-09-19 18:11 UTC
Requires
- longman/ip-tools: ~1.1.0
- monolog/monolog: ~1.23.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- symfony/var-dumper: *
This package is auto-updated.
Last update: 2024-08-28 10:01:27 UTC
README
这是一个简单的防火墙,可以保护您的Web应用程序免受多种攻击
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
composer require karster/firewall:"dev-master"
或者
"karster/firewall": "dev-master"
将以下内容添加到您的 composer.json 的 require 部分中。
用法
require __DIR__ . '/vendor/autoload.php'; $config = [ 'logDirectory' => __DIR__ . "/firewall_logs", 'logFilesCount' => 10, 'allowAttackCount' => 5, 'active' => true, 'protection' => [ 'allowedRequestMethod' => [ 'active' => true ], 'allowedGlobals' => [ 'active' => false ], 'urlLength' => [ 'active' => true, 'rules' => 200, ], 'getProtection' => [ 'active' => true, 'rules' => ['select', 'from'], ], 'urlProtection' => [ 'active' => true, 'rulesFile' => 'path/to/rulesFile.json' ], 'whitelistIp' => [ 'active' => true, 'rules' => ['127.0.0.1', '::1'] ], 'blacklistIp' => [ 'active' => true, 'rules' => ['23.254.0.1', '22.23.22.8'] ] ] ]; $firewall = new \karster\security\Firewall($config); $firewall->run();
或者
require __DIR__ . '/vendor/autoload.php'; $protections = [ 'allowedRequestMethod' => [ 'active' => true ], 'allowedGlobals' => [ 'active' => false ], 'urlLength' => [ 'active' => true, 'rules' => 200, ], 'getProtection' => [ 'active' => true, 'rules' => ['select', 'from'], ], 'urlProtection' => [ 'active' => true, 'rulesFile' => 'path/to/rulesFile.json' ], 'whitelistIp' => [ 'active' => true, 'rules' => ['127.0.0.1', '::1'] ], 'blacklistIp' => [ 'active' => true, 'rules' => ['23.254.0.1', '22.23.22.8'] ] ]; $firewall = new \karster\security\Firewall(); $firewall->setAllowAttackCount(5) ->setActive(true) ->setLogDirectory(__DIR__ . "/firewall_logs") ->setLogFilesCount(10) ->setProtection($protections) ->run();
- logDirectory -
string
- 防火墙可写入的目录路径 - logFilesCount -
integer
- 删除比特定数量更旧的日志。设置0
以禁用 - allowAttackCount -
integer
- 在黑名单之前来自同一IP地址的攻击计数(需要 logDirectory)。设置0
以禁用 - active -
boolean
- 默认true
- protection -
array
- 关联数组,其中键是保护名称,值是保护配置
保护
我们可以选择不同的保护类型
- allowedRequestMethod
- allowedGlobals
- blacklistIp
- cookieProtection
- getProtection
- postProtection
- sessionProtection
- urlLength
- urlProtection
每个保护都包含具有参数的配置数组
- active
boolen
- 默认true
- rules
array|integer
- 除了 urlLength 保护(它接受整数)之外,每个保护都接受数组 - rulesFile
string
- 包含规则的json文件路径
'cookieProtection' => [ 'active' => true, 'rules' => [ 'select', 'from', 'where' ], // or 'rulesFile' => 'path/to/rulesFile.json' ]
如果没有设置 rules
或 rulesFile
,则使用默认规则。
测试
./vendor/bin/phpunit -c phpunit.xml
贡献
有想法?发现了错误?请参阅 如何贡献。
许可证
MIT 查看 LICENSE 获取完整的许可文本。