backend
の次のWebプロジェクトでLaravel
を使用する予定です。 Laravelのビルトイン機能を使用して、API
サービスを構築します。だから今私の主な関心事は、そのようなサービスのセキュリティについてです。ミドルウェアを抑制するLaravelのAPIは、使いやすいソリューションだと思われますが、必要な柔軟性はあまりありません。少なくとも、シナリオを処理できるかどうかはわかりません。APIサービスの不正使用を防ぐ
ここに私の質問があります。うまくいけば誰かが答えてくれるはずです。
ユーザーがログに記録されているかどうかによって異なる調整ロジックを適用できますか? (2-3のスロットルチェックを実行する)または同じリクエスト内で複数の異なるスロットルチェックを実行する。
APIを呼び出すIPに関する履歴はどこに保存されていますか?それはHTTPヘッダーかcache/memcached/redisのようなものですか?
私がIPを禁止し、それが禁止されているかどうかをチェックしたいのであれば、この種の情報を保存する方法についての良いチュートリアルはありますか?どのようにスロットリングと統合するのですか?スキーマの例または何か?
- ルート:
GET: /api/invoice/1
ルール:
アドバイスの作品は、ここで- ルート:
:)は、私が最終的に実装したいロジックの簡単な例ですが良いでしょう
if IP throttling is enabled
then I don't want to check whether user is logged in or not
if (user is unauthorized) {
throttle by IP.
Throttle after 10 attempts within 1 minute
if (number of times throttled within last 5 minutes = 0) {
Retry-After: 1 minute
}
else if (number of times throttled within last 10 minutes > 1) {
Retry-After: 10 minutes
}
else if (number of times throttled within last 30 minutes > 3) {
Retry-After: 3 hours
}
else if (number of times throttled within last 8 hours minutes > 6) {
ban IP for 1 week!!!
}
}
else (user is authorised) {
if (has permission: get_invoices) {
throttle by JWT token.
Throttle after 100 attempts within 1 minute
if (number of times throttled within last 5 minutes = 0) {
Retry-After: 5 minutes
}
else if (number of times throttled within last 30 minutes > 1) {
ban user!!!
}
}
else (user is logged in but doesn't have necessary permission
{
throttle by JWT token.
Throttle after 50 attempts within 1 minute
// apply logic different from user who has permission
}
}
ルートNr 2、3、4の場合、それは全く異なるロジックになる可能性があります。
だから私はそれがsingleeパラメータに基づいているため、この例のように1つだけのミドルウェアを使用することはできません(それはIP、WTD、ドメインまたは他のこと)と禁止ロジック
のいずれかをincluseていませんRoute::group(['prefix' => 'api', 'middleware' => 'throttle:2,5'], function() {
Route::get('invoice/{id}', function() {
return $some invoice;
});
});
この件に関するフィードバックをいただきたいと思います。私はグローバルに行くことを計画しています:)
1:はい、可能です。 2:HTTPはステートレスなので、制限/抑制のためにIPアドレスの履歴を保存するのはあなた次第です(ユーザーのIPはいつでも変更でき、ISPによって割り当てられたIPなどの共有IPを割り当てることができますさまざまな時間に異なるユーザーに送信するので、信頼性の高い方法ではありません)。 3:2への回答を参照 – GordonM