突然、今まで動いた POST メソッド API が動かなくなり、タイトルのようにエラーが発生しました。
エラー内容はこんな感じ
Sorry, you have been blocked
You are unable to access ...
Why have I been blocked?
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
What can I do to resolve this?
You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.
Cloudflare Ray ID: .... • 10:21 Your IP: Click to reveal ... • Performance & security by Cloudflare
どうやら、Cloudflare 側が Managed rules に引っかかってブロックしているようです。※ 今まで動いたのに。。。
View related Firewall Events
をクリックすると、具体的なルールがわかりそうですが、RuleID で検索してもなにも出てこないです。困りましたね。
色々調べ、 949110 というエラーは複数のルールに引っかかっている場合に発生するようです。特に SQL Injection とか不正なデータがおくると発生するようです。 ※ ん、今まで動いたのに。。。送るデータも変わらないはずです。
対応
明確な理由がわからないので、いろんな対応を試しました。Cloudflare の設定を変更することができないので、クライアント側で対応しました。
結論下記の対応で動くようになりました。
- 送ってるデータを base64 エンコーディングします。
- 全部じゃなくて、例えば url とか、怪しいデータだけでも良いと思います。徹底的にやるならbody全部をbase64 エンコード
- オリジンサーバには base64 デコードしてから処理するようにします。
- Header の ContentType を明確に指定します。
-
application/json
とか、application/x-www-form-urlencoded
とか
-