aalfiann/url-param-firewall
为Slim Framework 3提供的PSR7中间件,用于URL参数防火墙
1.0.1
2018-09-27 13:08 UTC
Requires
- php: >=5.5
This package is auto-updated.
Last update: 2024-09-28 05:13:57 UTC
README
为Slim Framework 3提供的PSR7中间件,用于URL参数防火墙。
为什么我们需要为URL参数创建防火墙?
- 防止针对随机URL参数的ddos第7层攻击。
- 防止无用的网页缓存。
- 避免机器人访问错误的URL。
- 加强CSRF和XSS攻击的防御。
- 等等。
因此,最好为每个路由白名单URL参数。
安装
通过Composer安装此包。
composer require "aalfiann/url-param-firewall:^1.0"
使用
use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; use \aalfiann\middleware\ParamFirewall; $app->get('/', function (Request $request, Response $response) { $body = $response->getBody(); $body->write('You will see this message if passed url firewall'); return $response->withBody($body); })->(new ParamFirewall(['_','page']))->setName("/");
打开浏览器并现在进行测试
http://yourdomain.com/ >> 工作正常
http://yourdomain.com/?page=1 >> 工作正常
http://yourdomain.com/?page=1&_=3123123 >> 工作正常
http://yourdomain.com/?product=test >> 404
http://yourdomain.com/?page=1&_=3123123&product=test >> 404
注意
我们应该允许URL参数名称_
,因为它在jQuery AJAX缓存中使用。