Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

User Agent Blocking

最終更新 Markdown で表示Agent セットアップ

User Agent Blocking を使うと、特定のブラウザーまたは Web アプリケーションの User-Agent リクエストヘッダー をブロックできます。ユーザーエージェントルールは、個々のサブドメインではなく、ドメイン全体に適用されます。

ユーザーエージェントルールは、Zone Lockdown ルール のあとに適用されます。Zone Lockdown で IP アドレスを許可すると、その IP はユーザーエージェントルールをスキップします。

利用可否

Cloudflare の User Agent Blocking は、すべてのプランで利用できます。User agent rules オプションは、ユーザーエージェントルールを 1 つ以上設定している場合にだけ表示されます。

利用できるユーザーエージェントルールの数は、Cloudflare のプランによって異なります。

Free Pro Business Enterprise
利用可否 あり あり あり あり
ルール数 10 50 250 1,000

User Agent Blocking ルールを作成する

  1. Cloudflare ダッシュボードで Security rules ページを開きます。

    Security rules を開く ↗
  2. Create rule > User agent rules を選択します。

  3. Name/Description に、わかりやすいルール名を入力します。

  4. Action で、実行するアクションを選びます。BlockNon-Interactive ChallengeManaged ChallengeInteractive Challenge のいずれかです。

  5. User Agent にユーザーエージェントの値を入力します(* などのワイルドカードは使えません)。たとえば Bad Bot の Web スパイダーをブロックする場合は、BadBot/1.0.2 (+http://bad.bot) を入力します。

  6. Save and Deploy blocking rule を選択します。

Create a User Agent Blocking rule 操作に対して、次のような POST リクエストを送ります。

Required API token permissions

At least one of the following token permissions is required:
  • Firewall Services Write
Create a User Agent Blocking rulebash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/firewall/ua_rules" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"description": "Block Bad Bot web spider",
		"mode": "block",
		"configuration": {
				"target": "ua",
				"value": "BadBot/1.0.2 (+http://bad.bot)"
		}
	}'

チャレンジアクション

User Agent Blocking ルールが Managed Challenge などのチャレンジアクションを使う場合、訪問者はチャレンジページを通過する必要があります。通過すると cf_clearance Cookie が設定されます。この Cookie の有効期間は、Challenge Passage の設定で決まります。

関連リソース

役に立ちましたか?