CloudflareWAF と仲良くなれるまで

※画像はイメージです
この記事は CADDi Tech/Product Advent Calendar 2025 の11日目の記事です。
こんにちは、プロダクトセキュリティの方から来ました。
弊社ではお客様に安全に弊社サービスを使っていただくため、セキュリティ対策の一環としてWeb Application Firewallを導入しています。
がっ、CloudflareWAFちゃんは、なかなかのツンデレちゃんで、CloudflareWAFちゃんがツンからデレるまでの戦いの記録です。
はじめに
Cloudflare Web Application Firewall (以下Cloudflare WAF)内には、いくつかの機能があり、
その中に含まれるManaged rulesのCloudflare Managed RulesetとCloudflare OWASP Core Rulesetを中心に説明します。
Cloudflare Managed rulesetsとは?
Cloudflareが提供する、ゼロデイ脆弱性・OWASP TOP10の攻撃手法・漏洩した資格情報の使用、などから保護するための構成されたマネージド ルールセットです。
ルールセットは定期的に更新され、各ルールには、ルールの重要度に応じて異なるデフォルトのアクションが設定されています。
Cloudflare Managed rulesets の中には、以下の様なルールセットが含まれています。
-
Cloudflare Exposed Credentials Check
- Deploy an automated credentials check on your end-user authentication endpoints. For any credential pair, the Cloudflare WAF performs a lookup against a public database of stolen credentials. Cloudflare recommends that you use leaked credentials detection instead of this ruleset.
- Ruleset ID:
...14069605
-
Cloudflare Managed Ruleset
- Created by the Cloudflare security team, this ruleset provides fast and effective protection for all of your applications. The ruleset is updated frequently to cover new vulnerabilities and reduce false positives.
- Ruleset ID:
...376e9aee
-
Cloudflare Exposed Credentials Check
- Deploy an automated credentials check on your end-user authentication endpoints. For any credential pair, the Cloudflare WAF performs a lookup against a public database of stolen credentials. Cloudflare recommends that you use leaked credentials detection instead of this ruleset.
- Ruleset ID:
...14069605
-
Cloudflare Free Managed Ruleset
- Available on all Cloudflare plans. Designed to provide mitigation against high and wide impacting vulnerabilities. The rules are safe to deploy on most applications. If you deployed the Cloudflare Managed Ruleset for your site, you do not need to deploy this managed ruleset.
- Ruleset ID:
...dfb893ba
-
Cloudflare Sensitive Data Detection:
- The following managed rulesets run in a response phase:
- Created by Cloudflare to address common data loss threats. These rules monitor the download of specific sensitive data — for example, financial and personally identifiable information.
- Ruleset ID:
...499d988e
Cloudflare OWASP Core Ruleset と Cloudflare Managed Rulesetの詳細
以下では、Cloudflare OWASP Core Ruleset と Cloudflare Managed Rulesetの詳細についてです。
Cloudflare OWASP Core Ruleset
機能概要
挙動
- OWASP ModSecurity Core Rule Set に基づいて構成されたルールセット
- ルールセットは定期的に更新され、更新内容はChangelogとして記載される
- OWASPに連動しているので、更新頻度は低そう(所感)
- OWASP Core Ruleset内にあるルールに該当アクセスにするスコアリング(ポイント加算)される
- 適用されるルールは、Paranoia level(後述)によって定義される
- ルール単位で個別に有効・無効も可能
- 閾値(Score threshold)以上のものが、アクション(OWASP Action)に沿って処理される
- 閾値に該当したアクセスはログ中のDescriptionセクションに
949110: Inbound Anomaly Score Exceededと出力される- スコアに該当するルールは、ログ中のscore_rulesのセクションに出力される
OWASP Anomaly Score Threshold
- ルールに基づいてスコアリングされた接続の閾値
OWASP Paranoia Level
- Cloudflare OWASP Core Ruleset 内でのルール組み合わせアセット
- PL4 = PL1+PL2+PL3+PL4
- PL3 = PL1+PL2+PL3
- PL2 = PL1+PL2
- PL1 = PL1
| paranoia-level-1 rules (107) | paranoia-level-2 rules (44) | paranoia-level-3 rules (18) | paranoia-level-4 rules (7) | |
|---|---|---|---|---|
| PL4 | Disabled | Disabled | Disabled | Enabled |
| PL3 | Disabled | Disabled | Enabled | Enabled |
| PL2 | Disabled | Enabled | Enabled | Enabled |
| PL1 | Enabled | Disabled | Enabled | Enabled |
OWASP Action
- ルール単位でのアクションの設定は不可
- ルールセット単位でしか設定が行えない
- アクションには以下の選択ができる
| Action | Description | Terminating action? |
|---|---|---|
| Interactive Challenge API value: challenge | Useful for ensuring that the visitor accessing the site is human, not automated.The client that made the request must pass an interactive challenge.If successful, Cloudflare accepts the matched request; otherwise, it is blocked. | Yes |
| JS Challenge API value: js_challenge | Useful for ensuring that bots and spam cannot access the requested resource; browsers, however, are free to satisfy the challenge automatically.The client that made the request must pass a Cloudflare JavaScript Challenge before proceeding.If successful, Cloudflare accepts the matched request; otherwise, it is blocked. | Yes |
| Managed Challenge (Recommended) API value: managed_challenge | Helps reduce the lifetimes of human time spent solving CAPTCHAs across the Internet.Depending on the characteristics of a request, Cloudflare will dynamically choose the appropriate type of challenge from the following actions based on specific criteria:Show a non-interactive challenge page (similar to the current JS Challenge).Show a custom interactive challenge (such as click a button). | Yes |
| Block API value: block | Matching requests are denied access to the site. | Yes |
| Log API value: log | Records matching requests in the Cloudflare Logs.Only available on Enterprise plans.Recommended for validating rules before committing to a more severe action. | No |
Cloudflare Managed Ruleset
Cloudflare Managed Ruleset の機能概要と、設定値についての詳細です
機能概要
挙動
- Cloudflareのセキュリティチームが作成したルールセット
- ルールセットは定期的に更新され、更新内容はChangelogとして記載される
- 特定のアプリケーションに対するルールが、タグで管理されている、後述Tag configuration
- ルールセットでのアクションの設定が可能
- ルール単位でのアクションの設定が可能
- ルールセットでのアクションの指定を上書き
Ruleset action
- ルールセット全体および、ルールに対するアクションの設定
| Action | Description | Terminating action? |
|---|---|---|
| Interactive Challenge API value: challenge | Useful for ensuring that the visitor accessing the site is human, not automated.The client that made the request must pass an interactive challenge.If successful, Cloudflare accepts the matched request; otherwise, it is blocked. | Yes |
| JS Challenge API value: js_challenge | Useful for ensuring that bots and spam cannot access the requested resource; browsers, however, are free to satisfy the challenge automatically.The client that made the request must pass a Cloudflare JavaScript Challenge before proceeding.If successful, Cloudflare accepts the matched request; otherwise, it is blocked. | Yes |
| Managed Challenge (Recommended) API value: managed_challenge | Helps reduce the lifetimes of human time spent solving CAPTCHAs across the Internet.Depending on the characteristics of a request, Cloudflare will dynamically choose the appropriate type of challenge from the following actions based on specific criteria:Show a non-interactive challenge page (similar to the current JS Challenge).Show a custom interactive challenge (such as click a button). | Yes |
| Block API value: block | Matching requests are denied access to the site. | Yes |
| Log API value: log | Records matching requests in the Cloudflare Logs.Only available on Enterprise plans.Recommended for validating rules before committing to a more severe action. | No |
| Default | Default applies each rule's default action. |
Ruleset status
- すべてのルールを「有効」に設定すると、この管理対象ルールセットに将来追加されるルールを含め、デフォルトで無効になるルールが上書きされる。
Tag configuration
- 特定のアプリケーションに対するルールが、タグで管理されている
- 例
- Wordpress
- Drupal
- ほか
- 例
運用
実際にしばらく運用した際の注意点や所感など
適用ルールと誤検知
Cloudflare Managed Ruleset には複数のアプリケーションに対するルールセットが含まれており、
WAF配下で稼働していないアプリケーションAに対するルールが、
実際に稼働しているアプリケーションBでは誤検知として発生するケースがありました。
誤検知が発生した場合は、以下の様な対応をしました
- Tag configuration にて適用のルールを絞る
- 特定のパス・条件などを適用外とする(後述)
- 後述のログには2種類がり、どちらのログ中にもRuleIDとディスクリプションとしてルールの概要が含まれているので、どのルールにマッチしたか?の切り分けが行えます
特定のパス等を除外したい
セキュリティ観点ではできる限り除外はしたくないですが、特定のパターンに基づいた除外設定が必要な場合
- ルール・マネージドルールの中で、特定の条件に沿った除外設定はできない
- 別途、除外ルールをManaged Ruleset の前段に作成する
サンプル
When incoming requests match…
- ドメイン名 sample.com パス名 /abc01 と /dfg02を除外したい
(http.host eq "sample.com" and (http.request.uri.path eq "/abc01" or http.request.uri.path eq "/dfg02"))
Then…
- Skip all remaining rules
- すべてのManaged Rulesを除外したい場合
- Skip specific rules from a Managed Ruleset
- 特定のRulesetのみを除外したい場合(Rulesetに含まれるRule単体の指定は不可)
Managed Rulesのアップデート
ルールセットは定期的に更新され、各ルールには、ルールの重要度に応じて異なるデフォルトのアクションが設定されています。
Managed Rules は定期的に更新されます。(概ね週1回ぐらい)
更新・追加されるルールは、ログモードで追加されますが、ルールの内容によってはBlockモードで追加される場合もあり、更新内容の確認が必要になります。
また、
If you do notice a new or updated rule generating an increased volume of security events, you can disable or change the rule from its Default action. Once you change a rule to use an action other than the default one, Cloudflare will not be able to override the rule action.
ルールのアクションをDefault以外にしていた場合、そちらが優先されるため意図しないActionの変更が発生する可能性があります
WAFログの確認
運用していく上でWAFのログ確認や、ログに基づいた統計、分析なども必要ですが、
CloudflareのDashboardではやや厳しいと感じる点があり、
Datadogなどのログ管理ツールにて別途可視化するのが効率的です。
弊社ではDatadogに転送しDatadog上のDashboardにて分析などを行っています。
また、Cloudflareのログには、Cloudflareに対するログとCloudflareWAFのログが別途あり、CloudflareWAF ログのみの場合、ルールにマッチしたアクセスのみログ出力されるため、
切り分けなどのためにも、双方のログ確認が必要になります。
まとめ
- 日本語での情報が少なく、初期の調査などは苦労しました。
- ルール単位での細かなカスタマイズなど、小回りが効かない点は感じました。
- マネージドルールとなりルールないの細かなシグネチャが明記されていないため、誤検知などが発生した際に、なぜ誤検知が出たのか?の調査は困難です。これはCloudflareに限らず、マネージドルール全般言えることで、仕方ない部分はあるとは思います。
- マネージドルールとして提供されており、広い範囲でカバー可能なルールセットがあり、ルール自体のアップデートも定期的に実施されているため、ある程度手放しで運用できる点はメリットです
- (WAF製品全般的にそれぞれ)運用していく上で癖やメリット・デメリットがありますが、ある程度手放しで運用でき、最新のトレンドにも追従できている仕組みが、Cloudflareをすでに利用していればある程度簡単に導入できる点、運用においても著しい運用負荷の増加がない点は非常にありがたいです。
最初は「あ、この子ちょっととっつきにくいかなー」って思ってたんだよね。
でも、仲良くなりたいならまずは相手のこと知るのが大事だなって改めて気づいて。
ちゃんと向き合ってみたら、今ではすっかり仲良しになれたんだ。よかったぁ。
それじゃあ、みんなも素敵なメリークリスマスを過ごしてね❤️

※画像はイメージです
Discussion