Skip to content

Commit

Permalink
Add config to skip recaptcha.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasasr1 committed Jul 25, 2024
1 parent 6d6c11f commit d5aa20c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.wso2.carbon.identity.captcha.util.CaptchaUtil;
import org.wso2.carbon.identity.governance.IdentityGovernanceService;

import java.util.List;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -66,7 +68,9 @@ public boolean canHandle(ServletRequest servletRequest, ServletResponse servletR

String path = ((HttpServletRequest) servletRequest).getRequestURI();

if (StringUtils.isBlank(path) || (!CaptchaUtil.isPathAvailable(path, SELF_REGISTRATION_INITIATE_URL) &&
List<String> reCaptchaBypassedApiEndpoints = CaptchaDataHolder.getInstance().getReCaptchaBypassedApiEndpoints();
if (StringUtils.isBlank(path) || reCaptchaBypassedApiEndpoints.contains(path) ||
(!CaptchaUtil.isPathAvailable(path, SELF_REGISTRATION_INITIATE_URL) &&
!CaptchaUtil.isPathAvailable(path, SELF_REGISTRATION_URL))) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class CaptchaDataHolder {

private boolean forcefullyEnabledRecaptchaForAllTenants;

private List<String> reCaptchaBypassedApiEndpoints = new ArrayList<>();

private CaptchaDataHolder() {

}
Expand Down Expand Up @@ -268,4 +270,14 @@ public void setForcefullyEnabledRecaptchaForAllTenants(boolean forcefullyEnabled

this.forcefullyEnabledRecaptchaForAllTenants = forcefullyEnabledRecaptchaForAllTenants;
}

public List<String> getReCaptchaBypassedApiEndpoints() {

return reCaptchaBypassedApiEndpoints;
}

public void setReCaptchaBypassedApiEndpoints(List<String> reCaptchaBypassedApiEndpoints) {

this.reCaptchaBypassedApiEndpoints = reCaptchaBypassedApiEndpoints;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class CaptchaConstants {
public static final String CAPTCHA_RISK_ANALYSIS = "riskAnalysis";
// Captcha Types.
public static final String RE_CAPTCHA_TYPE_ENTERPRISE = "recaptcha-enterprise";
public static final String RE_CAPTCHA_BYPASSED_API_ENDPOINTS = "recaptcha.bypassed.api.endpoints";

// Default value for threshold for score in reCAPTCHA v3.
public static final double CAPTCHA_V3_DEFAULT_THRESHOLD = 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ private static void setReCaptchaConfigs(Properties properties) {
}
CaptchaDataHolder.getInstance().setReCaptchaRequestWrapUrls(reCaptchaRequestWrapUrls);

String reCaptchaBypassedApiEndpointsString = properties.getProperty(
CaptchaConstants.RE_CAPTCHA_BYPASSED_API_ENDPOINTS);
if (StringUtils.isNotBlank(reCaptchaBypassedApiEndpointsString)) {
CaptchaDataHolder.getInstance().setReCaptchaBypassedApiEndpoints(
Arrays.asList(reCaptchaBypassedApiEndpointsString.split(",")));
}

try {
Double reCaptchaScoreThreshold = getReCaptchaThreshold(properties);
CaptchaDataHolder.getInstance().setReCaptchaScoreThreshold(reCaptchaScoreThreshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ recaptcha.failed.redirect.urls={{recaptcha.redirect_urls}}
#recaptcha.failed.redirect.urls=
[]

{% if recaptcha.bypassed_api_endpoints is defined %}
# reCaptcha bypassed API endpoints
{% set bypassed_api_endpoints = recaptcha.bypassed_api_endpoints %}
recaptcha.bypassed.api.endpoints={{ bypassed_api_endpoints | join(',') }}
{% endif %}

# recaptcha request wrapping paths comma separated
recaptcha.request.wrap.urls={{recaptcha.request_wrap_urls}}

Expand Down

0 comments on commit d5aa20c

Please sign in to comment.