25
25
import java .util .Collection ;
26
26
import javax .servlet .http .HttpServletRequest ;
27
27
import org .forgerock .json .JsonValue ;
28
- import org .owasp .esapi .ESAPI ;
29
28
30
29
/**
31
30
* 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) {
77
76
DEBUG .message ("Validating goto URL " + url + " against patterns:\n " + patterns );
78
77
}
79
78
80
- // JavaScript URIs are a common vector for XSS attacks.
81
- if (url .toLowerCase ().startsWith ("javascript:" )) {
79
+ if (url .length () > MAX_URL_LENGTH ) {
82
80
return false ;
83
81
}
84
82
85
83
try {
86
84
final URI uri = new URI (url );
87
85
// Both Absolute and scheme relative URLs should be validated.
88
86
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 ;
91
92
}
92
93
} catch (final URISyntaxException urise ) {
93
94
if (DEBUG .messageEnabled ()) {
@@ -96,10 +97,6 @@ public boolean isRedirectUrlValid(final String url, final T configInfo) {
96
97
return false ;
97
98
}
98
99
99
- if (!ESAPI .validator ().isValidInput ("isRedirectUrlValid" , url , "URL" , MAX_URL_LENGTH , false )) {
100
- return false ;
101
- }
102
-
103
100
if (patterns == null || patterns .isEmpty ()) {
104
101
if (DEBUG .messageEnabled ()) {
105
102
DEBUG .message ("There are no patterns to validate the URL against, the goto URL is considered valid" );
0 commit comments