Discover How reCAPTCHA v3 and Cloud Armor Can Protect your Website

Discover advanced bot prevention strategies using reCAPTCHA v3 and Cloud Armor. Safeguard your website with CommIT Smart's insightful guide...

Strengthen your website security using Google’s reCAPTCHA Enterprise and Cloud Armor

Using Google's reCAPTCHA Enterprise, you can prevent spam and abuse on your website. Action tokens are one of the features of reCAPTCHA Enterprise, which allows you to control how reCAPTCHA is used.

The purpose of this article is to explain how Action Tokens can be used with Cloud Armor. Additionally, we will show you how to configure reCAPTCHA Enterprise with Terraform.
Comparison between reCAPTCHA Enterprise Action Tokens and other features

reCAPTCHA action-tokens

  • Use Case: Specifically designed to safeguard distinct user actions, such as login attempts or comment submissions.

  • Supported Platforms: Works seamlessly on both websites and mobile applications.

  • Integration Complexity: Classified as a medium. For successful deployment:

The reCAPTCHA JavaScript needs to be incorporated into the respective pages of your website or by using the reCAPTCHA Enterprise mobile SDK for mobile applications.

  1. The action token must be attached to each individual request header.

  2. Configurations must be made either on Google Cloud Armor security policy rules or through reCAPTCHA firewall policies when working with third-party WAF service providers.

  • Detection Accuracy: Positioned at the pinnacle with the highest accuracy due to its focus on individual user actions.

reCAPTCHA session-tokens

Use Case: Unlike action tokens, which protect specific user actions, session tokens cover an entire user session on a domain.

  • Supported Platforms: Session-tokens are limited to websites, while action-tokens also support mobile applications.

  • Integration Complexity: Both are medium, but session-tokens don’t require attaching an action token to request headers.

  • Detection Accuracy: While action-tokens offer the highest level of accuracy by focusing on individual actions, session-tokens have high accuracy, as they monitor the entire user session.

  • Supported Version: Both utilize reCAPTCHA Enterprise score-based site keys, but action-tokens also support checkbox site keys.

reCAPTCHA challenge page:

Use Case: Contrary to the action tokens that work in the background, the challenge page interrupts user activities and forces them to complete a CAPTCHA challenge when suspicious activity is detected.

  • Supported Platforms: Both are designed for websites.

  • Integration Complexity: Challenge page integration is low and more straightforward than action-tokens. It does away with JavaScript installations on individual pages.

  • Detection Accuracy: The challenge page has medium accuracy, a step down from the action tokens, primarily because it may miss some page-specific signals.

  • Supported Version: The challenge page uses an optimized version of reCAPTCHA, different from the Enterprise score-based or checkbox site keys supported by action tokens.

reCAPTCHA WAF express protection:

Use Case: It’s a go-to when your environment isn’t friendly with reCAPTCHA JavaScript or mobile SDKs, unlike action tokens that require these integrations.

  • Supported Platforms: WAF express protection is the most versatile, catering to APIs, IoT devices, websites, and mobile apps. Action-tokens cover just websites and mobile apps.

  • Integration Complexity: Both have low complexity, but the integration methods differ. Action-tokens require JavaScript or SDK installations, while WAF express can be set up with third-party WAFs or server requests.

  • Detection Accuracy: WAF express has the lowest detection accuracy since it lacks client-side signals. In contrast, action tokens boast the highest accuracy.

  • Supported Version: Both utilize reCAPTCHA Enterprise score-based site keys.

Steps to implement the solution

First let's create a reCAPTCHA v3 key on Google Cloud console. Security -> reCAPTCHA Enterprise -> Create Key

1.png

After defining the reCAPTCHA key basic parameters we should define some key behavior of the key.

2.png

3.png

To ensure the utmost security, enabling domain verification is highly recommended. However, it’s essential to note that if you’re integrating the key with Cloud Armor, direct support isn’t available at this moment (Issue Tracker for details). To address this, you’ll need to specify this behavior manually in your rules, which I will guide you through in the subsequent sections.

After setting up the key, we dive into the coding phase.

The mechanism we’ll implement is straightforward. When an action token reaches the load balancer, the designated Cloud Armor service will evaluate it. We primarily work with two parameters:

token.recaptcha_action.valid token.recaptcha_action.score

More about reCAPTCHA token attributes for Google Cloud Armor. If a request lacks the token, the valid parameter will automatically register as false. Under these circumstances, you have the discretion to determine the request's subsequent journey. In our implementation, we will append a MISSING value to our reCAPTCHA-Warning header. On the other hand, if the token is present, our focus shifts to the score parameter. This metric provides insights into the user, essentially estimating the likelihood of the requester being a bot or a genuine user. A score exceeding 0.8 will instruct the rule to dispatch the LOW value to the backend within the reCAPTCHA-Warning header. Should it fall below this threshold, a HIGH value gets transmitted instead.

Equipped with this data, our backend service can judiciously decipher the value and determine the subsequent course of action.

Setting up the security policy


This snippet initializes a Cloud Armor Edge security policy. Here, we’re defining a new Google Cloud Platform (GCP) security policy resource named “default-security-policy” for Cloud Armor at the edge. More about [google_compute_security_policy] (https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_security_policy)resource.

Configuring reCAPTCHA options


Within our security policy, we’re incorporating reCAPTCHA options. The redirect_site_key parameter is assigned the reCAPTCHA site key. Terraform resource documentation.

The rule for handling missing tokens


This rule targets requests that don’t contain a valid reCAPTCHA action token. If the token is absent or not valid, a new header named reCAPTCHA-Warning with the value MISSING is appended to the request.

The rule for handling low reCAPTCHA scores


This rule targets requests with reCAPTCHA scores greater than 0.8, which indicates probable genuine user interactions. As a result, the reCAPTCHA-Warning header is set to LOW, representing a low bot likelihood

Domain verification

If the domain doesn’t align with expectations, the rule could either reject or reroute the request. It’s advisable to trigger this undesired pattern rule prior to the reCAPTCHA check, thereby filtering out any undesirable requests before they undergo reCAPTCHA assessment. Once Google resolves the integration issue between reCAPTCHA and Cloud Armor related to the Domain Verification feature, it’s advisable to remove this anti-pattern from the rules.

The expression !request.headers['host'].matches('www.example.com') is used to detect requests that don't originate from the domain www.example.com.

rule {
  action   = "allow"
  priority = "1001"
  match {
    expr {
      expression = "!request.headers['host']

Add verification on a user interaction

Once we are done with the infrastructure part, we are ready to integrate our apps. Here is a integration from an example frontend application provided by Google.

To load reCAPTCHA Enterprise on your webpage, add the JavaScript API with your score-based key within the <head></head> element of your web page.

<head>
    <script src="https://www.google.com/recaptcha/enterprise.js?render=KEY_ID"></script>
    ....
</head>
  1. To ensure that grecaptcha.enterprise.execute() runs when the reCAPTCHA library loads, use grecaptcha.enterprise.ready().

  2. Call grecaptcha.enterprise.execute() on each interaction, you want to protect with your score-based key. Specify a meaningful name for a user interaction in the action parameter. For more guidance, see Actions.

<script>
function onClick(e) {
  e.preventDefault();
  grecaptcha.enterprise.ready(async () => {
    const token = await grecaptcha.enterprise.execute('KEY_ID', {action: 'LOGIN'});
    // IMPORTANT: The 'token' that results from execute is an encrypted response sent by
    // reCAPTCHA Enterprise to the end user's browser.
    // This token must be validated by creating an assessment.
    // See https://cloud.google.com/recaptcha-enterprise/docs/create-assessment
  });
}
</script>

grecaptcha.enterprise.execute() generates a token as shown in the following example:

03AGdBq27tvcDrfiRuxQnyKs-SarXVzPODXLlpiwNsLqdm9BSQQRtxhkD-Wv6l2vBSnL_JQd80FZp3IeeF_TxNMrqhyQchk7hmg_ypDctt_F5RTr9zNO9TSDX3Fy0qHQTuaM9E3hrAkA1v1l7D-fCreg7uq8zoudfh1ZRmN49-2iAMAn4E8_ff-nmlLTNGVZmCSyeze-5xM24pM_JhhUVcCMIDKYtDUnr2imxg2ubIqMscCZGUtdXNUO_LRSzuwWDlLyAr3V2nVn29Z48PQa2QzbymEXzO9pCtoGQmY7kiZ8ILfD9DAJSSyUTMwJXVJptUeBmLM341fq_STYZBbPQJ0zYOEDvJoFsIwGMfuphkDet0nK56b0mkzaL8RCRy2oK31Mcx6n3PhGkCnQ6QIhiV5ZVmV1Hz9M3w99zYw6ekc3wPCNMZ6V6x1ApVpIk3reFfByRQ0C0_pRWwbKZHLXQ_oSTI1UI7kyH1VeXngsJAx2l7zcp0hQNipajC4YwL7Jb8X4cCD0NeiaY1YCrI5j87mK5axcMikq460I4niIFeDBlHGF-ndqu3CJstosAur-C_x827f-dPPjA9Vrw8MDb3x4KUb0vbA8xE9mJxPYGY0rPCR27vJ38Voa7DjEBGX9c-iufv5_wfj-yIfIAHy0iijnRLI0CVkWF2-iPdWv7LnkTwL3WKbF_MrEGZXmtyLX9dEZArfxmToeMuSdYkfikkgR2-k4Xzxlz15RbHJuWSAYqEyTTnpUXmOvDuTN92b0kYqbRelcLUI_Shm-8dq9e-L7K6YWQv32gV6NukZKY15dyrJaW10frBgTOGSTTpIyB7MNEL8S27WjWtOb-zWsgimIhoRNfS8BiJWkmK4gTj51m7Wur-qsDbHgV6gXlMvjJs_B7oXX-mKsKhY9ACtwukotBelGYQOvf1RDHjH3Yi1RDfELBY6AkwUK4tq8cACVGpCwa0gKUo-sbORTsGu_r7VTzYo1AaZD5HV4XUm8yoqszel6DmIfkJcI7PfzzvfUJuvMQ1itZSzpzuth3glbKBYsIjbKqG-q8cxtZ7u0l32j46ASo2zlCJWUjwP3W1P7MUenEoIZtjlyTB_tT6Fk8RxGgRv3oLP7NPFJGs9ZGOAl6tBHpZF8Y_FqEOCMKtBl2JYOE5h6_Es3buSdiMm7mtLr64pboGiEColF1vbVvYpyaaqGFPXBM6ekZSXEXLAI0_7rj_fCLgnB21KXfac95vZbM9vyJCASvDcWKwqajQwy5aGMNe9GtbMogYbZfz5UGWAIi24Vd8KSv3qKOOwvzbcw4H0HYdsBXA After the token is generated, send the reCAPTCHA token to the backend and create an assessment within two minutes.

Conclusion

As bot activities become increasingly sophisticated, website and application owners must stay a step ahead. While our journey through this integration has showcased its strengths and potential areas for improvement, the key takeaway remains: with the right tools and informed strategies, we can build more secure, efficient, and user-friendly digital platforms.

As Google continues to refine and enhance its services, we can expect even more streamlined integrations and functionalities. Until then, let’s make the best of what we have, always prioritizing user experience while ensuring top-notch security.

Sources

  • https://cloud.google.com/recaptcha-enterprise

  • https://cloud.google.com/recaptcha-enterprise/docs/token-attr-ca

  • https://cloud.google.com/recaptcha-enterprise/docs/instrument-web-pages#user-action

  • https://cloud.google.com/recaptcha-enterprise/docs/waf-features#features-overview

  • https://issuetracker.google.com/issues/281859602

  • https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/recaptcha_enterprise_key

  • https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_security_policy

Author: Csaba Ujvári

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

Jun 20, 2024

Search Query Validation with React Router 6 and Yup and Typescript

Do you validate search queries in your frontend app? The answer is “sometimes”, but if you think of the search query as input for the application, you will change your mind.

Jan 28, 2024

How to Choose Between Monolithic Code and Microservices

Decipher Microservices vs. Monolithic Code: Choose wisely for a seamless development journey. Plan, embrace flexibility and avoid pitfalls. Insights from a DevOps developer.

Jan 28, 2024

Website vs Web Application: Which One Do You Need?

Decipher Microservices vs. Monolithic Code: Choose wisely for a seamless development journey. Plan, embrace flexibility and avoid pitfalls. Insights from a DevOps developer.

Sep 14, 2023

A Guide to Keeping Dependencies Up-to-Date for Enhanced Security and Efficiency in Development

Learn the importance of keeping dependencies up-to-date for a secure and efficient development process...

Sep 14, 2022

No Code Pro / Contra

No-code has caused an unusual, disruptive revelation and changes in the tech space – especially coding. Are programmers and coding still relevant or not?

Aug 14, 2022

Here are Some Reasons Why You Should Become a Software Engineer

Yes, software engineering is a good job based on virtually any criteria, including salary, the number of job openings, as well as overall job satisfaction...

Jul 14, 2022

A Guide to Working Remotely at Sea: Best Practices

Putting some effort into planning will make your entire trip more enjoyable. If you’re independently setting sail, plot a course that takes your availability into account.

Jun 14, 2022

11 Essential Skills to Become a Software Developer in 2022

Key skills for programmers and software developers to learn in 2022. If you have been doing software development for some time and thinking about what makes a good programmer?

Aug 16, 2023

How to Implement Request Validation with OAPI-Codegen and Go for Robust Development

Several of our projects require back-end as well as front-end work. If a client wants us to create RESTful APIs, we start by using the OpenAPI 3 specification.

Aug 31, 2023

The Best Way to Optimize Serverless Computing

Explore the latest features of Cloud Run for seamless deployment and scaling...

Oct 12, 2023

How to Effortlessly Automate SSL Deployment with Lego and Kubernetes

Automate SSL certificate management seamlessly with Lego and Kubernetes. Learn efficient deployment practices for a secure web environment at CommIT Smart...

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.