AWS WAF のルールビルダーで複数の否定条件を設定する方法を教えてください

2021.09.03

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

困っていた内容

AWS WAF でルールグループを使っていて、複数のパス(/aaa/, /bbb/)をブロック条件から除外したいです。

NOT ルールステートメントを含むルールを作成すればよいと考えましたが、NOT ルールステートメントでは 2 つ以上の条件を指定することができません。

2 つ以上の否定条件は作成できないのでしょうか?もしやり方があれば方法を教えてください。

どう対応すればいいの?

ルールビルダーで 2 つ以上の否定条件は作成できます。

WAF コンソール上の「If a request」の項目で「doesn't match the statement (NOT)」を選択すると 1 つしか条件が設定できません。

2 つ以上の条件を設定するには、matches all the statements (AND)matches at least one of the statements (OR)を選択し、Negate statement resultsをチェックします。

matches all the statements (AND) の設定手順例を記載します。

  1. AWS WAF ルールビルダーの編集画面を開く
  2. 「Rule」の項目で Name を入力
  3. 「If a request」の項目で matches all the statements (AND) を選択
  4. 「Statement 1」の「Negate statement (NOT)」の項目で「Negate statement results」をチェック(項目名が NOT Statement 1 に変わる)
  5. 「Statement 1」の条件を適宜入力
    • Inspect: URI Path
    • Match type: Contains string
    • String to match: /aaa/
  6. 「Statement 2」の「Negate statement (NOT)」の項目で「Negate statement results」をチェック(項目名が NOT Statement 2 に変わる)
  7. 「Statement 2」の条件を適宜入力
    • Inspect: URI Path
    • Match type: Contains string
    • String to match: /bbb/
  8. 「Then」の項目で Action を選択
  9. 「Add rule」ボタンをクリック

参考資料