aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Proper CAPTCHA error Handling in client-cognito-identity-provider

Open achrafsouk opened this issue 5 months ago • 8 comments

Describe the feature

When Cognito user pool is used with an AWS WAF that includes a CAPTCHA, there is no proper way to detect a 405 response code signaling to the front end to display AWS WAF CAPTCHA.

As a workaround, I check the error message if it contains the 'captcha' keyword to trigger the CAPTCHA rendering in the frontend. This is not a great long term solution.

Use Case

Protecting a Cognito endpoint with CAPTCHA.

Proposed Solution

The best is to have a CAPTCHA error type that can be caught and properly handled in the front end.

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

SDK version used

v4

Environment details (OS name and version, etc.)

Mac

achrafsouk avatar Aug 15 '25 07:08 achrafsouk

@achrafsouk SDK Version Clarification: The AWS SDK for JavaScript only has v2 and v3 versions. Could you please confirm which version you're using?

Additional Information Needed: To help us investigate this issue, could you provide:

  1. Minimal code example showing how you're making the Cognito request
  2. Complete error object you receive (including error code, message, and any additional properties) and the Expected behavior vs Observed behavior.

smilkuri avatar Aug 15 '25 11:08 smilkuri

Sorry it was a typo, I meant v3.

Here's a code snippet https://github.com/achrafsouk/cognito-signup-page/blob/2a25122e18c65721065d766b9cbf70e992e1e3c9/src/index.js#L85

Instead of a generic error, I'd like to catch a specific exception when a 405 response code is received due to a CAPTCHA in AWS WAF, such as CaptchaRequestedException

achrafsouk avatar Aug 15 '25 16:08 achrafsouk

Hi @achrafsouk - a list of service exceptions for this command can be found on this API docs. I'm not sure which one you're looking to catch but SDK probably won't be able to add custom exception.

aBurmeseDev avatar Aug 18 '25 20:08 aBurmeseDev

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] avatar Aug 29 '25 00:08 github-actions[bot]

Hello @aBurmeseDev

The error that the SDK should catch corresponds to a 405 error code, returned by Cognito when the associated WAF WebACL is requesting a valid CAPTCHA token, which usually prompt the frontend to trigger a CAPTCHA UI.

This is a valid use case that should be caught by a specific Exception so that the frontend can know that it's related to CAPTCHA and renders the CAPTCHA appropriately.

achrafsouk avatar Aug 31 '25 08:08 achrafsouk

I'm sorry I'm not following your use case here. Which specific exception are you asking SDK to catch and which service exception is being returned by Cognito? Could you elaborate further? You may look at these service exceptions messages and catch the specific one like you're doing in your code. But note that none of the messages include "captcha".

aBurmeseDev avatar Sep 04 '25 17:09 aBurmeseDev

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] avatar Sep 15 '25 00:09 github-actions[bot]

Hello @aBurmeseDev ,

The error code that I am talking about is not listed in the service exception page that you shared with me. When a WAF WebACL is asscoiated with a Cogntio user pool, and it sends back CAPTCHA challenge, Cognito endpoint returns 405 HTTP response code. This is important error to be properly caught by the SDK. We should have an associated service exception, such as:

CaptchaChallengeReturned This exception is thrown when the AWS AWF WebACL associated with Amazon Cognito returns a CAPTCHA challenge. HTTP status code: 405.

HTTP Status Code: 405

achrafsouk avatar Sep 16 '25 05:09 achrafsouk