Skip to content

Commit ada30aa

Browse files
committed
Add validation to Back to Application URL
1 parent dfb5ecd commit ada30aa

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

identity-apps-core/apps/recovery-portal/src/main/webapp/username-recovery-complete.jsp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<%@ page import="org.wso2.carbon.identity.application.authentication.endpoint.util.AuthenticationEndpointUtil" %>
2424
<%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.client.IdentityRecoveryException" %>
2525
<%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.IdentityManagementEndpointUtil" %>
26+
<%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.client.PreferenceRetrievalClient" %>
27+
<%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.client.PreferenceRetrievalClientException" %>
28+
<%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.client.ApplicationDataRetrievalClient" %>
2629
<%@ page import="java.io.File" %>
2730
<%@ page import="java.net.URISyntaxException" %>
2831
<%@ taglib prefix="layout" uri="org.wso2.identity.apps.taglibs.layout.controller" %>
@@ -57,6 +60,28 @@
5760
successMessageTitle = "username.recovery.sms.success.heading";
5861
successMessageDescrition = "username.recovery.sms.success.body";
5962
}
63+
64+
boolean isValidCallBackURL = true;
65+
66+
try {
67+
isValidCallBackURL = AuthenticationEndpointUtil.isSchemeSafeURL(callback);
68+
69+
if (isValidCallBackURL && StringUtils.isNotBlank(callback)) {
70+
ApplicationDataRetrievalClient applicationDataRetrievalClient = new ApplicationDataRetrievalClient();
71+
String applicationAccessUrl = applicationDataRetrievalClient.getApplicationAccessURL(tenantDomain, spAppName);
72+
73+
if (StringUtils.isNotBlank(applicationAccessUrl)) {
74+
// If the application access URL is present, only then allow the callback to be that URL.
75+
isValidCallBackURL = StringUtils.equals(callback, applicationAccessUrl);
76+
} else {
77+
// If the application access URL is not present, callback should be a valid multi option URL.
78+
String encodedCallback = IdentityManagementEndpointUtil.getURLEncodedCallback(callback);
79+
isValidCallBackURL = AuthenticationEndpointUtil.isValidMultiOptionURI(encodedCallback);
80+
}
81+
}
82+
} catch (Exception e) {
83+
isValidCallBackURL = false;
84+
}
6085
%>
6186

6287
<% request.setAttribute("pageName", "username-recovery-complete"); %>
@@ -101,7 +126,7 @@
101126
<%=i18n(recoveryResourceBundle, customText, successMessageDescrition)%>
102127
<br><br>
103128
<%
104-
if(StringUtils.isNotBlank(callback) && AuthenticationEndpointUtil.isSchemeSafeURL(callback)) {
129+
if (StringUtils.isNotBlank(callback) && isValidCallBackURL) {
105130
%>
106131
<br/><br/>
107132
<i class="caret left icon primary"></i>

0 commit comments

Comments
 (0)