AWS WAF の Contains string と Contains word の違いについて検証してみた

AWS WAF(Web Application Firewall)は、ウェブアプリケーションを外部からの攻撃から守るために設計されたサービスです。
WAFを設定する際、ユーザーはさまざまな条件に基づいてリクエストを検査するルールを作成できます。
その中でよく使われる「Match type」という設定オプションがあります。
この設定は、WAFがリクエストに対してどのようにパターンマッチングを行うかを決定します。
「Match type」の中でも「Contains string」と「Contains word」は似ていますがドキュメントを確認しても具体的な動作の違いがイメージ出来ず、具体的な検証結果をお伝えしていきたいと思います。
目次
検証方法
検証を行うために、以下の前提で実験を行いました。
【WAF設定】
◎ Rule Type
Regular rule
◎Inspect
Single header
◎Header field name
waf-check-parameter
◎Match type
Contains string
Contains word
※検証毎に切り替え
◎String to match
bad word
◎Text transformation
None
◎Action
Block
【リクエスト方法】
下記の様なcurlコマンドにて検証します。
$ curl -I -H "waf-check-parameter:[リクエスト文字列]" https://[検証用FQDN]/
またリクエスト文字列には以下4つを使います。
「This contains a bad word」
「badwording」
「This is badword example」
「This is word example」
Contains stringでの検証
◎「This contains a bad word」(一致)
$ curl -I -H "waf-check-parameter:This contains a bad word" https://[検証用FQDN]/
HTTP/2 403
server: CloudFront
date: Tue, 15 Apr 2025 13:29:05 GMT
content-type: text/html
content-length: 919
x-cache: Error from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎「badwording」(不一致)
$ curl -I -H "waf-check-parameter:badwording" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:29:59 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎「This is badword example」(不一致)
$ curl -I -H "waf-check-parameter:This is badword example" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:30:56 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎ 「This is word example」(不一致)
$ curl -I -H "waf-check-parameter:This is word example" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:34:07 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
「This contains a bad word」のみ一致したことから、半角スペースを含めた文字列の部分一致で検査していることがわかります。
Contains wordでの検証
◎「This contains a bad word」(不一致)
$ curl -I -H "waf-check-parameter:This contains a bad word" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:46:54 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎「badwording」(不一致)
$ curl -I -H "waf-check-parameter:badwording" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:46:57 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎「This is badword example」(不一致)
$ curl -I -H "waf-check-parameter:This is badword example" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:47:00 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎ 「This is word example」(不一致)
$ curl -I -H "waf-check-parameter:This is word example" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:47:03 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
全リクエストが不一致という結果になりました。
個人的にはString to matchをスペースで分割した単語「bad」「word」とリクエスト文字列を分割した単語(例:「This」「contains」「a」「bad」「word」)で完全一致の検査をするのかなと予想していました。
Contains wordでの検証(ルール調整)
リクエスト文字列は変えず、 String to matchを「word」のみにして検証してみます。
◎「This contains a bad word」(一致)
$ curl -I -H "waf-check-parameter:This contains a bad word" https://[検証用FQDN]/
HTTP/2 403
server: CloudFront
date: Tue, 15 Apr 2025 13:54:53 GMT
content-type: text/html
content-length: 919
x-cache: Error from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎「badwording」(不一致)
$ curl -I -H "waf-check-parameter:badwording" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:54:56 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎「This is badword example」(不一致)
$ curl -I -H "waf-check-parameter:This is badword example" https://[検証用FQDN]/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Tue, 15 Apr 2025 13:54:58 GMT
server:
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-cache: Miss from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
◎ 「This is word example」(一致)
$ curl -I -H "waf-check-parameter:This is word example" https://[検証用FQDN]/
HTTP/2 403
server: CloudFront
date: Tue, 15 Apr 2025 13:55:01 GMT
content-type: text/html
content-length: 919
x-cache: Error from cloudfront
via: 1.1 ******.cloudfront.net (CloudFront)
x-amz-cf-pop: ******
x-amz-cf-id: ******
「This contains a bad word」と「This is word example」が一致しました。
「badwording」と「This is badword example」が不一致という点から、リクエスト文字列をスペースで分割して完全一致での検査をしていそうです。
AWS WAFルール検証(まとめ)
単語レベルでの検査は自作しようと思うと自然言語処理を学ぶ必要があり、導入難度的に良い機能だなと思う反面どういう用途があるか思いつきませんでした。
WCUを気にしないのであれば、基本的にContains stringを使った複合・複数ルールで実装になってしまいそうです。
今回ご紹介した AWS WAFの設定をはじめ、ターン・アンド・フロンティアでは AWS をご利用されているお客様に技術的なご支援が可能ですので、AWS WAFの活用にご興味のある方はお問い合わせフォームよりお気軽にご相談ください。

元記事発行日: 2025年11月19日、最終更新日: 2025年11月06日















