Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Este documento mostra exemplos de como implementar os recursos do
reCAPTCHA para WAF no Cloud Armor.
É possível usar um ou mais recursos do reCAPTCHA para WAF em um único
aplicativo.
Se você quiser usar mais de um recurso, crie uma chave reCAPTCHA
para cada um deles e use-as no seu aplicativo. Por exemplo, se você
quiser usar tokens de ação reCAPTCHA e a página de teste do reCAPTCHA, crie
uma chave de token de ação e uma chave de página de teste e use-as no seu
aplicativo.
Exemplo 1: como usar tokens de sessão reCAPTCHA e a página de teste do reCAPTCHA
É possível adicionar um token de sessão reCAPTCHA às páginas que um usuário pode acessar.
Assim, o cookie é atualizado periodicamente. Isso se aplica a, por exemplo, uma página de login.
Configure uma regra de política de segurança do Cloud Armor para redirecionar a solicitação para
uma página de teste do reCAPTCHA quando a pontuação for baixa.
A ilustração a seguir mostra um fluxo de trabalho que usa recursos da página de teste
e um token de sessão reCAPTCHA
Exemplo 2: como usar tokens de ação reCAPTCHA e a página de teste do reCAPTCHA
É possível adicionar um token de ação reCAPTCHA para proteger uma ação do usuário, como a finalização de uma compra.
Configure uma regra de política de segurança do Cloud Armor para redirecionar a solicitação a
uma página de teste do reCAPTCHA em qualquer uma das seguintes condições:
A pontuação é baixa.
O atributo action_name do token de ação não corresponde à ação protegida
do usuário.
A ilustração a seguir mostra um fluxo de trabalho que usa recursos da página de teste
e um token de ação reCAPTCHA:
O exemplo de script a seguir mostra como usar um token de ação reCAPTCHA e
redirecionar para uma página de teste do reCAPTCHA com o token de ação anexado como cabeçalho:
<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 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>
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 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)."]]