Skip to content

Commit 3f8e1f0

Browse files
committed
OPENAM-8117 Fix checking of redirection URLs created internally
1 parent d54084a commit 3f8e1f0

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

openam-server-only/src/main/webapp/oauth2c/OAuthLogout.jsp

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
try {
8787
SSOToken ssoToken = manager.createSSOToken(request);
8888
String realm = ssoToken.getProperty("Organization");
89-
boolean isValidGotoUrl = AuthD.getAuth().isGotoUrlValid(gotoURL, realm);
89+
boolean isValidGotoUrl = AuthD.getAuth().isGotoUrlValid(gotoURL, realm)
90+
&& ESAPI.validator().isValidInput("URLContext", gotoURL, "HTTPURI", 2000, false);
9091
if (!isValidGotoUrl) {
9192
OAuthUtil.debugError("OAuthLogout: invalid or empty goto URL ignored on Logout page: " + gotoURL);
9293
gotoURL = ServiceURI + "/UI/Logout";
@@ -95,6 +96,7 @@
9596
OAuthUtil.debugMessage("OAuthLogout: using default goto URL because we failed to get a session");
9697
gotoURL = ServiceURI + "/UI/Logout";
9798
}
99+
gotoURL = ESAPI.encoder().encodeForJavaScript(gotoURL);
98100
99101
String logoutURL = request.getParameter(PARAM_LOGOUT_URL);
100102
if (logoutURL == null) {
@@ -112,6 +114,7 @@
112114
doYouWantToLogout = doYouWantToLogout.replace("#IDP#", OAuth2IdP);
113115
}
114116
}
117+
logoutURL = ESAPI.encoder().encodeForJavaScript(logoutURL);
115118
String copyrightNotice = null;
116119
try{
117120
copyrightNotice = ResourceBundle.getBundle("amAuthUI", locale).getString("copyright.notice");

openam-shared/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@
157157
<artifactId>java-ipv6</artifactId>
158158
</dependency>
159159

160-
<dependency>
161-
<groupId>external</groupId>
162-
<artifactId>esapiport</artifactId>
163-
</dependency>
164-
165160
<dependency>
166161
<groupId>org.testng</groupId>
167162
<artifactId>testng</artifactId>

openam-shared/src/license/THIRD-PARTY.properties

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919
#
2020
#
2121
#Tue Jan 12 15:44:33 GMT 2016
22-
external--esapiport--2013-12-04=BSD
2322
external--jss4--2007-08-11=MPL

openam-shared/src/main/java/org/forgerock/openam/shared/security/whitelist/RedirectUrlValidator.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Collection;
2626
import javax.servlet.http.HttpServletRequest;
2727
import org.forgerock.json.JsonValue;
28-
import org.owasp.esapi.ESAPI;
2928

3029
/**
3130
* Validates the provided redirect URL against the list of valid goto URL domains.
@@ -77,17 +76,19 @@ public boolean isRedirectUrlValid(final String url, final T configInfo) {
7776
DEBUG.message("Validating goto URL " + url + " against patterns:\n" + patterns);
7877
}
7978

80-
// JavaScript URIs are a common vector for XSS attacks.
81-
if (url.toLowerCase().startsWith("javascript:")) {
79+
if (url.length() > MAX_URL_LENGTH) {
8280
return false;
8381
}
8482

8583
try {
8684
final URI uri = new URI(url);
8785
// Both Absolute and scheme relative URLs should be validated.
8886
if (!uri.isAbsolute() && !url.startsWith("//")) {
89-
return ESAPI.validator().isValidInput("isRedirectUrlValid", url, "HTTPURI", MAX_URL_LENGTH,
90-
false);
87+
return true;
88+
}
89+
90+
if (uri.getScheme() != null && !uri.getScheme().equals("http") && !uri.getScheme().equals("https")) {
91+
return false;
9192
}
9293
} catch (final URISyntaxException urise) {
9394
if (DEBUG.messageEnabled()) {
@@ -96,10 +97,6 @@ public boolean isRedirectUrlValid(final String url, final T configInfo) {
9697
return false;
9798
}
9899

99-
if (!ESAPI.validator().isValidInput("isRedirectUrlValid", url, "URL", MAX_URL_LENGTH, false)) {
100-
return false;
101-
}
102-
103100
if (patterns == null || patterns.isEmpty()) {
104101
if (DEBUG.messageEnabled()) {
105102
DEBUG.message("There are no patterns to validate the URL against, the goto URL is considered valid");

openam-shared/src/test/java/org/forgerock/openam/shared/security/whitelist/RedirectUrlValidatorTest.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ public void testRelativeUrlsWithoutWhitelist(String url, boolean result) {
232232
public Object[][] getJavaScriptCases() {
233233
return new Object[][]{
234234
{"javascript:alert", false},
235+
{"java%73cript:alert", false},
236+
{" javascript:alert", false},
235237
{"JavaSCRIpt:alert", false},
236238
{"/javascript:alert", true},
237239
};
@@ -252,15 +254,19 @@ public void testJavaScriptUrlsWithoutWhitelist(String url, boolean result) {
252254
@DataProvider(name = "malformed")
253255
public Object[][] getMalformedCases() {
254256
return new Object[][]{
255-
{"http:abc", false},
256-
{"http:/abc", false},
257-
{"/a$bc", false}
257+
{"/a bc", false},
258+
{"/a\"", false},
259+
// invalid protocol
260+
{"ftp://example.com", false},
261+
// This is an example of a redirect URL that OpenAM can produce
262+
{"http://example.com/openam/oauth2/authorize?nonce=1234&scope=test%20test2&response_type=code&"
263+
+ "client_id=myagent&redirect_uri=http%3A%2F%2Fgoogle.com", true}
258264
};
259265
}
260266

261267
@Test(dataProvider = "malformed")
262268
public void testMalformedUrlsWithWhitelist(String url, boolean result) {
263-
RedirectUrlValidator<String> validator = getValidator(asSet("http://example.com/*"));
269+
RedirectUrlValidator<String> validator = getValidator(asSet("http://example.com/*?*"));
264270
assertThat(validator.isRedirectUrlValid(url, null)).isEqualTo(result);
265271
}
266272

0 commit comments

Comments
 (0)