mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-03 23:25:52 +00:00
Merge branch 'security-stable-1.651' into security-master
This commit is contained in:
commit
888ca85784
9 files changed
+95
-3
No files matched your search
@@ -91,6 +91,8 @@ 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.
|
||||
@@ -1421,7 +1423,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
|
||||
@@ -1430,6 +1437,13 @@ public class Util {
|
||||
return idx<_indexOf(uri, '#') && idx<_indexOf(uri,'?') && idx<_indexOf(uri,'/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true iff the parameter does not denote an absolute URI and not a scheme-relative URI.
|
||||
*/
|
||||
public static boolean isSafeToRedirectTo(@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.
|
||||
|
||||
Reference in new issue
Block a user