[FIX SECURITY-276] Don't allow open redirect using scheme-rel. URL

This commit is contained in:
Daniel Beck committed 2016-04-25 19:50:53 +02:00
1 parent d6bcfdac70
commit 2ed0c046df
4 files changed
+17 -3

No files matched your search

+14
View File
@@ -77,6 +77,8 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.codec.digest.DigestUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
/**
* Various utility methods that don't have more proper home.
@@ -1454,7 +1456,12 @@ public class Util {
* The same algorithm can be seen in {@link URI}, but
* implementing this by ourselves allow it to be more lenient about
* escaping of URI.
*
* @deprecated Use {@code isAbsoluteOrSchemeRelativeUri} instead if your goal is to prevent open redirects
*/
@Deprecated
@RestrictedSince("1.651.2 / 2.TODO")
@Restricted(NoExternalUse.class)
public static boolean isAbsoluteUri(@Nonnull String uri) {
int idx = uri.indexOf(':');
if (idx<0) return false; // no ':'. can't be absolute
@@ -1463,6 +1470,13 @@ public class Util {
return idx<_indexOf(uri, '#') && idx<_indexOf(uri,'?') && idx<_indexOf(uri,'/');
}
/**
* Return true iff the parameter denotes an absolute URI, or a scheme-relative URI.
*/
public static boolean isAbsoluteOrSchemeRelativeUri(@Nonnull String uri) {
return isAbsoluteUri(uri) || uri.startsWith("//");
}
/**
* Works like {@link String#indexOf(int)} but 'not found' is returned as s.length(), not -1.
* This enables more straight-forward comparison.