1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[AWS] WAFマネージドルールのカスタマイズ

Last updated at Posted at 2022-05-06

概要

AWS REST API で展開しているWebアプリケーションにおいて、[403 ERROR The request could not be satisfied.]エラーが発生してしまった際の解決メモ

AWS構成

使用サービス

  • AWS
  • Lambda
  • API Gateway
  • CloudFront
  • WAF

構成

  • Lambda(PHP)をAPI Gateway(REST API)にて展開している
  • API GatewayはCloudFront経由で呼び出し
  • WAFをCloudFront、API Gatewayの前に設置
    • マネージドルール[AWSManagedRulesCommonRuleSet]をデフォルトのまま設定

Webアプリケーション/エラー発生個所

  • PHP8.0.17
  • エラー発生個所は画像ファイル(約1MB)を数枚アップロードしている処理内

エラー情報の詳細

  • PHPで記載したWebアプリケーションで画像ファイルなどをアップロードする箇所で以下のエラー発生

403 ERROR
The request could not be satisfied.
Request blocked. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

image.png

エラー調査

  • WAFのメトリクスを確認した所、BLOCKのログが確認されました。

    • AWS#AWSManagedRulesCommonRuleSet#SizeRestrictions_BODY
      image.png
  • AWS デベロッパーガイドにて仕様を確認

SizeRestrictions_BODY
リクエスト本文のサイズが最大 10,240 バイトであることを確認します。

  • 言い換えると、10,240 バイト(10KB)以上のリクエストを送信しようとしてWAFルールセットに引っかかってしまったようです。

エラー解決策

  • WAFマネージドルールをカスタマイズする事とします。
  • WAFルールにおいてはブロックモードからカウントモードに変更する事によって、検知するが、ブロックはしない挙動に変更できます。
    • WAFルール編集画面を開きます。
    • SizeRestrictions_BODYのルールアクションを[カウント]に変更
      image.png
    • [Save rule]をクリック

まとめ

  • AWS WAFマネージドルールは便利ですが、デフォルト設定のままだとWebアプリケーションが正常に挙動しない場合が有ります。
  • マネージドルールは適宜、見直しが必要です。
  • ルール検知はするが、ブロックしたくない場合は、[ブロックモード]から[カウントモード]への変更が必要です。
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?