Skip to content

Captcha feature enable/disable is ignored and captcha header is always sent #19655

Open
@sherrerohb

Description

@sherrerohb

Describe the bug
Captcha feature enable/disable is ignored and captcha header is always sent

Tell us the version of Spartacus
2211.28 (also happens on latest)

To Reproduce

  1. Implement captcha feature and make sure it is working
  2. Disable the captcha in backoffice (Base Commerce -> Base Store -> [select basestore] -> Disable 'Captcha Widget Enabled' toggle
  3. Register a new user in your app using Spartacus
  4. Check 'users' HTML request. sap-commerce-cloud-captcha-token header is still present

Expected behavior
sap-commerce-cloud-captcha-token header should only be sent if the 'Captcha Widget Enabled' toggle is enabled.

Desktop:

  • OS: Windows 11
  • Browser Chrome 131.0.6778.86

Explanation and Solution
OccUserProfileAdapter.appendCaptchaToken() creates a const isCaptchaEnabled to decide if the header should be sent. isCaptchaEnabled is a Subscription and will always resolve as truthy:

protected appendCaptchaToken(currentHeaders: HttpHeaders): HttpHeaders {
    if (this.injector && this.captchaConfig?.captchaRenderer) {
      const provider = this.injector.get<CaptchaRenderer>(
        this.captchaConfig.captchaRenderer
      );
      const isCaptchaEnabled = provider
        .getCaptchaConfig()
        .subscribe((config) => {
          return config.enabled;
        });

      if (provider?.getToken() && isCaptchaEnabled) { //isCaptchaEnabled is always truthy
        return currentHeaders.append(USE_CAPTCHA_TOKEN, provider.getToken());
      }
    }
    return currentHeaders;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions