View a markdown version of this page

CAPTCHA and Challenge action behavior - Amazon WAF, Amazon Firewall Manager, Amazon Shield Advanced, and Amazon Shield network security director
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Introducing a new console experience for Amazon WAF

You can now use the updated experience to access Amazon WAF functionality anywhere in the console. For more details, see Working with the console.

CAPTCHA and Challenge action behavior

This section explains what the CAPTCHA and Challenge actions do.

When a web request matches the inspection criteria of a rule with CAPTCHA or Challenge action, Amazon WAF determines how to handle the request according to the state of its token and immunity time configuration. Amazon WAF also considers whether the request can handle the CAPTCHA puzzle or challenge script interstitials. The scripts are designed to be handled as HTML content, and they can only be handled properly by a client that's expecting HTML content.

Note

You are charged additional fees when you use the CAPTCHA or Challenge rule action in one of your rules or as a rule action override in a rule group. For more information, see Amazon WAF Pricing.

How the action handles the web request

Amazon WAF applies the CAPTCHA or Challenge action to a web request as follows:

  • Valid token – Amazon WAF handles this similar to a Count action. Amazon WAF applies any labels and request customizations that you've configured for the rule action, and then continues evaluating the request using the remaining rules in the protection pack (web ACL).

  • Missing, invalid, or expired token – Amazon WAF discontinues the protection pack (web ACL) evaluation of the request and blocks it from going to its intended destination.

    Amazon WAF generates a response that it sends back to the client, according to the rule action type:

    • Challenge – Amazon WAF includes the following in the response:

      • The header x-amzn-waf-action with a value of challenge.

        Note

        JavaScript applications running in the client browser can read this header, including for cross-origin (cross-domain) requests. This is possible because Amazon WAF includes cross-origin resource sharing (CORS) headers in the response. For details, see the section that follows.

      • The HTTP status code 202 Request Accepted.

      • If the request contains an Accept header with a value of text/html, the response includes a JavaScript page interstitial with a challenge script.

    • CAPTCHA – Amazon WAF includes the following in the response:

      • The header x-amzn-waf-action with a value of captcha.

        Note

        JavaScript applications running in the client browser can read this header, including for cross-origin (cross-domain) requests. This is possible because Amazon WAF includes cross-origin resource sharing (CORS) headers in the response. For details, see the section that follows.

      • The HTTP status code 405 Method Not Allowed.

      • If the request contains an Accept header with a value of text/html, the response includes a JavaScript page interstitial with a CAPTCHA script.

To configure the timing of token expiration at the protection pack (web ACL) or rule level, see Setting timestamp expiration and token immunity times in Amazon WAF.

CORS headers in CAPTCHA and Challenge responses

Amazon WAF includes cross-origin resource sharing (CORS) headers in its CAPTCHA and challenge responses. CORS headers are a set of access control headers. They tell the client browser which domains, HTTP methods, and HTTP headers JavaScript applications can use. Amazon WAF sets the following CORS headers in the response:

access-control-allow-origin: * access-control-allow-methods: OPTIONS,GET,POST access-control-max-age: 86400 access-control-expose-headers: x-amzn-waf-action

Because access-control-expose-headers includes the x-amzn-waf-action header, JavaScript applications in the client browser can read it from the CAPTCHA and Challenge responses, including for cross-origin requests.

What the challenge and CAPTCHA interstitials do

When a challenge interstitial runs, after the client responds successfully, if it doesn't already have a token, the interstitial initializes one for it. Then it updates the token with the challenge solve timestamp.

When a CAPTCHA interstitial runs, if the client doesn't have a token yet, the CAPTCHA interstitial invokes the challenge script first to challenge the browser and initialize the token. Then the interstitial runs its CAPTCHA puzzle. When the end user successfully completes the puzzle, the interstitial updates the token with the CAPTCHA solve timestamp.

In either case, after the client responds successfully and the script updates the token, the script resubmits the original web request using the updated token.

You can configure how Amazon WAF handles tokens. For information, see Token use in Amazon WAF intelligent threat mitigation.