[扩展推荐] 使用 Laravel Shield 来保护你的 Webhook 不受入侵
Laravel Shield 是由 Ashley Clarke 开发的包,通过中间件实现了对来自第三方未经验证webhook的过滤。 这个包现在可以在Github, GitLab Stripe, 和 Zapier 下载,并且Pull Request处于开放状态,还在不断更新。
安装后,你可以在路由中使用这个中间件。
例如:
Route::middleware('shield:github')->post('/hooks/github', 'HooksController@github');
任何运行 following checks的路由请求都要通过 Shield GitHub
<?php
namespace Clarkeash\Shield\Services;
use Illuminate\Http\Request;
class GitHub extends BaseService
{
public function verify(Request $request): bool
{
$generated = 'sha1=' . hash_hmac('sha1', $request->getContent(), config('shield.services.github.token'));
return hash_equals($generated, $this->header($request, 'X-Hub-Signature'));
}
public function headers(): array
{
return ['X-Hub-Signature'];
}
}
查询 official repo获取更多Laravel Shield信息开始更容易的保护你的webhooks。
更新于 10/23/2017:
这个包已经被移到 Laravel Shield 下; 核心包与服务集成 现在已经被拆分为2个独立的仓库. 你可以在 laravel-shield.com找到更多资料.
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。
本帖已被设为精华帖!