この記事では、よくある疑問にできるだけお答えしました。まず最初のステップは、どのような保護システムが使われているかを特定することです。そのために、代表的なキャプチャやボット対策システムの一覧を参照できます。ここには、どの仕組みが使われているかを素早く見分けるための画面イメージや主な特徴がまとめられています。
もしサイトで reCAPTCHA v2 Enterprise が使われていることが分かったら、次のステップはその特徴と動作をより詳しく確認することです。同じこの記事の中で、reCAPTCHA v2 Enterprise をサイトに導入するための手順書も確認できるので、あなたのサイト上でどのように機能しているのかをしっかり理解できます。これにより、現在の保護を正しく把握できるだけでなく、今後の運用や保守も計画的に行えるようになります。
reCAPTCHA v2 Enterprise を含むフォームをテストする際は、キャプチャが正しく組み込まれ機能しているか確認する必要があります。
サイトに埋め込まれたキャプチャを手動で確認する方法
自動解決には CapMonster Cloud のようなツールを使うと便利です。キャプチャのパラメータを送信すると、サーバー側で処理して利用可能なトークンを返してくれます。そのトークンをフォームに挿入すれば、ユーザー操作なしでチェックを通過できます。
CapMonster Cloud API を使った一般的な手順:
リクエストには以下を含めます:
type - RecaptchaV2EnterpriseTask;
websiteURL - キャプチャが設置されているページの URL;
websiteKey - ページに記載された sitekey;
enterprisePayload - reCAPTCHA Enterprise の実装で、sitekey と共に grecaptcha.enterprise.render に追加の s フィールドを渡している場合に指定します;
pageAction - ウィジェットが Google に送る action 値(デフォルト verify).
https://api.capmonster.cloud/createTask{
"clientKey": "API_KEY",
"task": {
"type": "RecaptchaV2EnterpriseTask",
"websiteURL": "https://mydomain.com/page-with-recaptcha-enterprise",
"websiteKey": "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
"pageAction": "verify",
"enterprisePayload": {
"s": "SOME_ADDITIONAL_TOKEN"
}
}
}
{
"errorId":0,
"taskId":407533072
}https://api.capmonster.cloud/getTaskResult{
"clientKey":"API_KEY",
"taskId": 407533072
}
{
"errorId": 0,
"status": "ready",
"solution": {
"gRecaptchaResponse": "03AFcWeA66ZARdA5te7acD9vSwWE2hEQ2-B2aqFxm455iMA-g-Jis..."
}
}
import { chromium } from 'playwright';
import { CapMonsterCloudClientFactory, ClientOptions, RecaptchaV2EnterpriseRequest } from '@zennolab_com/capmonstercloud-client';
(async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
// 2. キャプチャのあるページを開く
await page.goto('https://example.com');
// 3. CapMonster Cloud クライアントを作成
const cmcClient = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: '<your_capmonster_cloud_api_key>' })
);
// 4. キャプチャ解決リクエストを構成
const recaptchaRequest = new RecaptchaV2EnterpriseRequest({
websiteURL: page.url(),
websiteKey: '6Lf76sUnAAAAAIKLuWNyegRsFUfmI-3Lex3xT5N'
// enterprisePayload: { s: 'SOME_ADDITIONAL_TOKEN' } // オプションの Enterprise パラメータ
});
// 5. CapMonster 経由でキャプチャを解く
const solution = await cmcClient.Solve(recaptchaRequest);
const token = solution.solution.gRecaptchaResponse;
console.log('キャプチャトークン:', token);
// 6. トークンを hidden フィールドに挿入
await page.evaluate((t) => {
const el = document.getElementById('g-recaptcha-response');
if (el) el.value = t;
}, token);
// 7. (任意) フォーム送信 — 必要に応じてセレクター変更
await page.click('button[data-action="submit"]');
await page.waitForTimeout(5000);
await browser.close();
})();reCAPTCHA Enterprise は Google Cloud 上で動作するため、まずはコンソールでプロジェクトを作成する必要があります。
1. Google Cloud Console にアクセスします。
2. 画面上部のメニューで既存のプロジェクトを選ぶか、新しいプロジェクトをクリックします。
3. プロジェクト名を入力し、組織を指定して作成を確定します。

4. 次に API ページ reCAPTCHA Enterprise API を開き、有効にする をクリックします。
5. コンソールの キーを作成 ページに移動し、キーを作成 をクリックします。

6. 基本設定を行います。
次に 追加の設定 を開き、チャレンジを使用しますか? をオンにして チェックボックス チャレンジ を有効にします。

7. 作成 をクリックします。保護を有効にするために、サイトに追加する必要があるキーが発行されます。

8. スクリプトをページに追加します。
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/enterprise.js" async defer></script>
</head>
<body>
<form action="" method="POST">
<div class="g-recaptcha" data-sitekey="YOUR_SITEKEY" data-action="LOGIN"></div>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>9. サーバー側でレスポンスを検証します。
トークン (g-recaptcha-response) はバックエンドに送信されます。
有効期限は 2 分です。受信したらすぐに検証してください! API との安全な通信には、公式の Google Cloud ライブラリの使用を推奨します。
<?php
require 'vendor/autoload.php';
// Composer で Google Cloud ライブラリをインストールします
use Google/Cloud/RecaptchaEnterprise/V1/RecaptchaEnterpriseServiceClient;
use Google/Cloud/RecaptchaEnterprise/V1/Event;
use Google/Cloud/RecaptchaEnterprise/V1/Assessment;
use Google/Cloud/RecaptchaEnterprise/V1/CreateAssessmentRequest;
use Google/Cloud/RecaptchaEnterprise/V1/TokenProperties/InvalidReason;
/**
* reCAPTCHA Enterprise トークンを検証し、リスク スコアを取得します。
*
* @param string $recaptchaKey サイト/アプリ用の reCAPTCHA キー
* @param string $token クライアントから受け取ったトークン
* @param string $projectId Google Cloud プロジェクト ID
* @param string $action トークンに関連付けられたアクション名
*/
function create_assessment(string $recaptchaKey, string $token, string $projectId, string $action): void {
$client = new RecaptchaEnterpriseServiceClient();
$projectName = $client->projectName($projectId);
// アセスメント イベントを作成します
$event = (new Event())->setSiteKey($recaptchaKey)->setToken($token);
$assessment = (new Assessment())->setEvent($event);
$request = (new CreateAssessmentRequest())->setParent($projectName)->setAssessment($assessment);
try {
$response = $client->createAssessment($request);
if (!$response->getTokenProperties()->getValid()) {
echo 'トークンが無効です: ' . InvalidReason::name($response->getTokenProperties()->getInvalidReason());
return;
}
if ($response->getTokenProperties()->getAction() === $action) {
echo 'リスク スコア: ' . $response->getRiskAnalysis()->getScore();
} else {
echo 'reCAPTCHA タグ内の action が期待される値と一致しません';
}
} catch (Exception $e) {
echo 'reCAPTCHA のチェック中にエラーが発生しました: ' . $e->getMessage();
}
}
// 変数を渡して関数を呼び出します
create_assessment(
'YOUR_SITE_KEY',
'YOUR_USER_RESPONSE_TOKEN',
'YOUR_PROJECT_ID',
'YOUR_RECAPTCHA_ACTION'
);
?>すでにキャプチャや別の保護システムが導入されているサイトを引き継いだものの、コードにはアクセスできない場合でも心配はいりません!どの技術が使われているかを特定するのはそれほど難しくありません。動作が正しいか確認するには、隔離されたテスト環境で認識サービスCapMonster Cloudを利用し、トークン処理の仕組みと検証ロジックが正しく機能しているかをチェックできます。
reCAPTCHA v2 Enterpriseの場合も、システムを特定し、その挙動を調べて、保護機能が正しく動いていることを確認すれば十分です。この記事では、reCAPTCHA v2 Enterpriseを見分ける方法と、その導入や再設定に関する手順書の見つけ方を紹介しました。これにより、防御を安心して維持し、その動作をしっかりと管理できます。