Skip to content

Introduce Google reCaptcha alternatives for IAM products #8199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 571 commits into
base: feature-recaptcha-alternatives
Choose a base branch
from

Conversation

KaveeshaPiumini
Copy link
Contributor

@KaveeshaPiumini KaveeshaPiumini commented May 15, 2025

Purpose

  1. This PR improves the existing Google reCaptcha implementation by refactoring it to automatically bind the challenge to a button without calling grecaptcha.execute() method when required.
  2. This PR refactors the captcha provider to dynamically render the captcha provider related UI components without the knowledge of the configured captcha provider. Previously google recaptcha, captcha provider engagement points were hardcoded where necessary.

Related Issues

Merge After

Related PRs

@wso2-jenkins-bot
Copy link
Contributor

⚠️ No Changeset found

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.

If these changes should result in a version bump, you need to add a changeset.

Refer Release Documentation to learn how to add a changeset.

@KaveeshaPiumini KaveeshaPiumini changed the base branch from master to feature-recaptcha-alternatives June 5, 2025 11:35
@KaveeshaPiumini KaveeshaPiumini marked this pull request as ready for review June 5, 2025 11:35
Comment on lines 470 to 471
if (scriptAttributesList != null) {
for (Map<String, String> scriptAttributes : scriptAttributesList) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (scriptAttributesList != null) {
for (Map<String, String> scriptAttributes : scriptAttributesList) {
if (scriptAttributesList != null) {
for (Map<String, String> scriptAttributes : scriptAttributesList) {

@NipuniBhagya NipuniBhagya requested a review from Copilot June 6, 2025 08:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the existing Google reCaptcha integration in various authentication and recovery JSP pages to a dynamic implementation using CaptchaFEUtils. Key changes include:

  • Replacing hardcoded reCaptcha API URLs, keys, and response parameters with dynamic values from CaptchaFEUtils.
  • Consistent rendering of captcha-related script and widget HTML using data from CaptchaFEUtils.
  • Updating header and form submission logic across multiple JSP files to support the new captcha integration.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
self-registration-without-verification.jsp Replaces reCaptcha API/script inclusion and widget attributes with dynamic CaptchaFEUtils values.
self-registration-with-verification.jsp Updates captcha headers and widget rendering using CaptchaFEUtils in place of reCaptchaUtil calls.
self-registration-username-request.jsp Switches captcha header addition from reCaptcha to CaptchaFEUtils.
password-recovery.jsp and related recovery pages Dynamically injects captcha script attributes and response identifiers using CaptchaFEUtils.
resend-confirmation-captcha.jsp, login.jsp, identifierauth.jsp, basicauth.jsp Refactors captcha widget rendering, form submission, and reset functionality to use CaptchaFEUtils.
Comments suppressed due to low confidence (1)

identity-apps-core/apps/authentication-portal/src/main/webapp/identifierauth.jsp:348

  • [nitpick] Ensure that all instances where the captcha site key is rendered (for example, in the identifierauth.jsp file) have been thoroughly tested to guarantee that the dynamic CaptchaFEUtils values are correctly injected and that the resulting HTML complies with the expected widget behavior.
data-sitekey="<%=Encode.forHtmlContent(captchaKey)%>"

grecaptcha.reset();
}
// Reset the captcha to allow another submission.
CaptchaFEUtils.getCaptchaFunctions().get("reset");
Copy link
Preview

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that the captcha reset function is being retrieved but not invoked. Please ensure that the reset function is correctly called (for example, by appending '()' if it’s a callable function) to properly reset the captcha UI on subsequent submissions.

Suggested change
CaptchaFEUtils.getCaptchaFunctions().get("reset");
CaptchaFEUtils.getCaptchaFunctions().get("reset")();

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CaptchaFEUtils.getCaptchaFunctions() returns a Map<String, String>, so get("reset") returns the function name as a string, not a callable. We’re just retrieving the function name here to be used in the frontend, not invoking it. Calling get("reset")() would throw an error since the value is a string, not a function.

@@ -32,6 +32,7 @@
<%@ page import="static org.wso2.carbon.identity.application.authentication.endpoint.util.Constants.ENABLE_AUTHENTICATION_WITH_REST_API" %>
<%@ page import="static org.wso2.carbon.identity.application.authentication.endpoint.util.Constants.ERROR_WHILE_BUILDING_THE_ACCOUNT_RECOVERY_ENDPOINT_URL" %>
<%@ page import="org.wso2.carbon.identity.captcha.util.CaptchaUtil" %>
<%@ page import="org.wso2.carbon.identity.captcha.provider_mgt.util.CaptchaFEUtils" %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we rename this util to CaptchaUIUtils?

data-sitekey="<%=Encode.forHtmlAttribute(reCaptchaKey)%>"
<div
<%
Map<String, String> captchaAttributes = CaptchaFEUtils.getWidgetAttributes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the reusable logics to a utils or helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, moving the logic to a helper or utility isn't straightforward because the code is tightly coupled with dynamic HTML rendering inside the JSP. Unlike JavaScript or modern templating engines, JSP doesn’t support returning reusable fragments easily — helpers would have to return raw HTML strings or write directly to the output stream, which is messy and not cleanly maintainable. While we could create custom JSP tags or tag files for better separation, that introduces additional complexity and multiple files just to handle small, context-specific logic blocks. Given that, keeping the current logic inline avoids overengineering and remains easier to follow for now in my point of view.


console.log("reCaptcha response: " + reCaptchaResponse);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove any unnecessary logs

pavinduLakshan and others added 22 commits June 18, 2025 11:20
Add new developer checklist to the PR template
[Release] [GitHub Action] Update package versions
github-actions bot and others added 30 commits June 28, 2025 07:36
[Release] [GitHub Action] Update package versions
[Release] [GitHub Action] Update package versions
Fix minor content issues in the 'Invite User to Set Password' flow
[Release] [GitHub Action] Update package versions
Support configuring Recovery Portal URL via branding settings and apply in Forgot Password link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.