{"canonical_url":"https://engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/","content_markdown":"# 異常時拒否のレート制限・不正利用対策を構築\n\nRedisによる22個のレートリミッター、Cloudflare Turnstile、リクエストの冪等性、オリジン制限を備え、異常時は拒否する不正利用対策を構築し、呼び出し元を無条件に信頼せずボットや大量アクセスを排除した。\n\n2025\n\n**状況.** 企業と専門家の公開一覧は、公開初日から標的になる。スクレイパーはデータを、迷惑アカウントは到達範囲を求め、検索、出力、外部APIなど実費がかかる機能も、無料で呼べるだけで悪用価値がある。特定の基盤への悪意でなく、公開インターネットの通常の環境だった。\n\n**課題.** 制限自身の依存先が落ちる圧力も含め、負荷のもとで保てる制限を、費用や悪用可能性の高い経路に設ける必要があった。\n\n**行動.** 全体に単一上限を置かず、守る経路ごとに22個の制限を設けた。ログイン、検索、大量出力では悪用となる頻度が大きく違う。状態はRedisに置き、プロセスごとで簡単に回避されずインスタンス間で共有する。Redisが不在なら、通すのでなく拒否する方を選んだ。不便でも正当化できる唯一の選択だった。周辺に、追加検証が必要な経路へのCloudflare Turnstile、再試行した書き込みを重複させない351行の冪等性middleware、正規入口を通らない要求を拒否するオリジン制限、一覧専用の独自チャレンジ検証を設けた。\n\n**結果.** 悪用者の費用を高く、基盤の費用を低くし、制限の保存先の障害は無制限開放でなく拒否へ縮退する。Redis問題が利用者に見える問題になることは、請求額の問題になるよりよいとして意図的に受け入れた。\n\n---\n\n- 役割: セキュリティエンジニア\n- カテゴリー: [バックエンド開発](https://platform.engineer.company/ja/categories/backend/), [API・システム連携](https://platform.engineer.company/ja/categories/api/), [信頼性・バックアップ](https://platform.engineer.company/ja/categories/reliability/), [ネットワーク・VPN](https://platform.engineer.company/ja/categories/networking/), [セキュリティ](https://platform.engineer.company/ja/categories/security/), [性能改善](https://platform.engineer.company/ja/categories/performance/)\n- サービス: [バックエンド・API開発](https://platform.engineer.company/ja/services/backend-development/), [サイト信頼性・監視](https://platform.engineer.company/ja/services/site-reliability/), [セキュリティ・アクセス管理](https://platform.engineer.company/ja/services/security-access/), [AIエージェントのセキュリティ](https://platform.engineer.company/ja/services/ai-security/)\n\n\u003chttps://engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/\u003e\n","date_modified":"2026-11-12T05:34:23Z","description":"Redisによる22レートリミッター、Cloudflare Turnstile、リクエストの冪等性、オリジン制限を備える、異常時拒否の不正利用対策を構築した。","formats":{"gemtext":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/index.gmi","gopher":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/gophermap","html":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/","json":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/index.json","markdown":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/index.md","pdf":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/index.pdf"},"kind":"page","language":"ja","title":"異常時拒否のレート制限・不正利用対策を構築","url":"https://platform.engineer.company/ja/portfolio/built-fail-closed-rate-limiting-and-anti-abuse/","version":1}