이 문서에서는 Google Cloud Armor에 WAF용 reCAPTCHA 기능을 구현하는 방법을 예시로 보여줍니다.
단일 애플리케이션에서 WAF용 reCAPTCHA 기능을 하나 이상 사용할 수 있습니다.
기능을 두 개 이상 사용하려면 기능마다 reCAPTCHA 키를 만들고 애플리케이션에서 사용해야 합니다. 예를 들어 reCAPTCHA 작업 토큰과 reCAPTCHA 테스트 페이지를 사용하려면 작업 토큰 키와 테스트 페이지 키를 만들고 애플리케이션에서 사용해야 합니다.
예시 1: reCAPTCHA 세션 토큰 및 reCAPTCHA 테스트 페이지 사용
사용자가 액세스할 수 있는 페이지에 reCAPTCHA 세션 토큰을 추가하여 쿠키가 주기적으로 새로고침되도록 할 수 있습니다(예: 로그인 페이지).
점수가 낮을 경우 Google Cloud Armor 보안 정책 규칙을 구성하여 요청을 reCAPTCHA 테스트 페이지로 리디렉션합니다.
다음 이미지는 reCAPTCHA 세션 토큰과 reCAPTCHA 테스트 페이지 기능을 사용하는 워크플로를 보여줍니다.
예시 2: reCAPTCHA 작업 토큰 및 reCAPTCHA 테스트 페이지 사용
reCAPTCHA 작업 토큰을 추가하여 결제와 같은 사용자 작업을 보호할 수 있습니다.
다음 조건에서 Google Cloud Armor 보안 정책 규칙을 구성하여 reCAPTCHA 테스트 페이지로 요청을 리디렉션합니다.
점수가 낮습니다.
작업 토큰의 action_name 속성이 보호되는 사용자 작업과 일치하지 않습니다.
다음 이미지는 reCAPTCHA 작업 토큰 및 reCAPTCHA 테스트 페이지 기능을 사용하는 워크플로를 보여줍니다.
다음 샘플 스크립트는 reCAPTCHA 작업 토큰을 사용하고 작업 토큰이 헤더로 연결된 reCAPTCHA 테스트 페이지로 리디렉션하는 방법을 보여줍니다.
<script src="https://www.google.com/recaptcha/enterprise.js?render=ACTION_TOKEN_SITE_KEY"></script>
<script>
function onSuccess(token) {
const xhr = new XMLHttpRequest();
xhr.open('GET','http://www.example.com/checkout', false);
xhr.setRequestHeader("X-Recaptcha-Token", token);
xhr.onreadystatechange = function() {
// Make sure that the request is finished and response is ready with 200
if (this.readyState == 4 && this.status == 200) {
// Display the response, it could be a reCAPTCHA challenge
// page based on your Google Cloud Armor security rule settings.
document.open();
document.write(xhr.responseText);
document.close();
}
};
xhr.send(null);
}
grecaptcha.enterprise.ready(function () {
document.getElementById("execute-button").onclick = () => {
grecaptcha.enterprise.execute('ACTION_TOKEN_SITE_KEY', {
}).then(onSuccess, onError);
};
});
</script>
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-31(UTC)"],[],[],null,["# Examples of integration with Google Cloud Armor\n\nThis document shows examples of how to implement the features of\nreCAPTCHA for WAF for Cloud Armor.\n\nYou can use one or more features of reCAPTCHA for WAF in a single\napplication.\nIf you want to use more than one feature, then you must create a reCAPTCHA key for each of those features and use them in your application. For example, if you want to use reCAPTCHA action-tokens and reCAPTCHA challenge page, then you must create an action-token key and a challenge-page key, and use them in your application.\n\n\u003cbr /\u003e\n\nExample 1: Using reCAPTCHA session-tokens and reCAPTCHA challenge page\n----------------------------------------------------------------------\n\nYou can add a reCAPTCHA session-token on pages that a user might access so\nthat the cookie gets refreshed periodically, for example, a login page.\nConfigure a Cloud Armor security policy rule to redirect the request to\na reCAPTCHA challenge page when the score is low.\n\nThe following illustration shows a workflow that uses reCAPTCHA session-token\nand reCAPTCHA challenge page features:\n\nExample 2: Using reCAPTCHA action-tokens and reCAPTCHA challenge page\n---------------------------------------------------------------------\n\nYou can add a reCAPTCHA action-token to protect a user action, such as checkout.\nConfigure a Cloud Armor security policy rule to redirect the request to\na reCAPTCHA challenge page in any of the following conditions:\n\n- The score is low.\n- The `action_name` attribute of the action-token does not match the user action that is protected.\n\nThe following illustration shows a workflow that uses reCAPTCHA action-token\nand reCAPTCHA challenge page features:\n\nThe following sample script shows how to use a reCAPTCHA action-token and\nredirect to a reCAPTCHA challenge page with the action-token attached as header: \n\n \u003cscript src=\"https://www.google.com/recaptcha/enterprise.js?render=ACTION_TOKEN_SITE_KEY\"\u003e\u003c/script\u003e\n \u003cscript\u003e\n function onSuccess(token) {\n const xhr = new XMLHttpRequest();\n xhr.open('GET','http://www.example.com/checkout', false);\n xhr.setRequestHeader(\"X-Recaptcha-Token\", token);\n xhr.onreadystatechange = function() {\n // Make sure that the request is finished and response is ready with 200\n if (this.readyState == 4 && this.status == 200) {\n // Display the response, it could be a reCAPTCHA challenge\n // page based on your Cloud Armor security rule settings.\n document.open();\n document.write(xhr.responseText);\n document.close();\n\n }\n };\n xhr.send(null);\n }\n\n grecaptcha.enterprise.ready(function () {\n document.getElementById(\"execute-button\").onclick = () =\u003e {\n grecaptcha.enterprise.execute('ACTION_TOKEN_SITE_KEY', {\n }).then(onSuccess, onError);\n };\n });\n \u003c/script\u003e\n\nWhat's next\n-----------\n\n- Learn how to [implement reCAPTCHA WAF features with Cloud Armor](https://codelabs.developers.google.com/codelabs/cloud-armor-recaptcha-bot-management).\n- Learn more about [features for integration with WAF service providers](/recaptcha/docs/waf-features)."]]