mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 19:16:42 +00:00
[FIXED SECURITY-77] XSS in iconSize cookie.
This commit is contained in:
1 parent
535c1115bb
commit
a0b00508ee
4 files changed
+15
-7
No files matched your search
@@ -123,6 +123,8 @@ import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
/**
|
||||
* Utility functions used in views.
|
||||
@@ -426,6 +428,15 @@ public class Functions {
|
||||
return c.getValue();
|
||||
}
|
||||
|
||||
private static final Pattern ICON_SIZE = Pattern.compile("\\d+x\\d+");
|
||||
@Restricted(NoExternalUse.class)
|
||||
public static String validateIconSize(String iconSize) throws SecurityException {
|
||||
if (!ICON_SIZE.matcher(iconSize).matches()) {
|
||||
throw new SecurityException("invalid iconSize");
|
||||
}
|
||||
return iconSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the suffix to use for YUI JavaScript.
|
||||
*/
|
||||
|
||||
@@ -766,7 +766,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
|
||||
|
||||
{
|
||||
StaplerRequest req = Stapler.getCurrentRequest();
|
||||
iconSize = req != null ? Functions.getCookie(req, "iconSize", "32x32") : "32x32";
|
||||
iconSize = req != null ? Functions.validateIconSize(Functions.getCookie(req, "iconSize", "32x32")) : "32x32";
|
||||
}
|
||||
|
||||
@Override protected void compute() throws Exception {
|
||||
|
||||
@@ -295,7 +295,6 @@ import java.util.logging.Level;
|
||||
import static java.util.logging.Level.SEVERE;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -3417,9 +3416,9 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro
|
||||
*/
|
||||
public void doIconSize( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
|
||||
String qs = req.getQueryString();
|
||||
if(qs==null || !ICON_SIZE.matcher(qs).matches())
|
||||
if(qs==null)
|
||||
throw new ServletException();
|
||||
Cookie cookie = new Cookie("iconSize", qs);
|
||||
Cookie cookie = new Cookie("iconSize", Functions.validateIconSize(qs));
|
||||
cookie.setMaxAge(/* ~4 mo. */9999999); // #762
|
||||
rsp.addCookie(cookie);
|
||||
String ref = req.getHeader("Referer");
|
||||
@@ -3964,8 +3963,6 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Jenkins.class.getName());
|
||||
|
||||
private static final Pattern ICON_SIZE = Pattern.compile("\\d+x\\d+");
|
||||
|
||||
public static final PermissionGroup PERMISSIONS = Permission.HUDSON_PERMISSIONS;
|
||||
public static final Permission ADMINISTER = Permission.HUDSON_ADMINISTER;
|
||||
public static final Permission READ = new Permission(PERMISSIONS,"Read",Messages._Hudson_ReadPermission_Description(),Permission.READ,PermissionScope.JENKINS);
|
||||
|
||||
@@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||
-->
|
||||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
|
||||
<j:set scope="parent" var="iconSize" value="${h.getCookie(request,'iconSize','32x32')}" />
|
||||
<j:set scope="parent" var="iconSize" value="${h.validateIconSize(h.getCookie(request,'iconSize','32x32'))}" />
|
||||
<!--
|
||||
balls look smaller than their actual size,
|
||||
so we try not to make the secondary icons look bigger than the icon.
|
||||
|
||||
Reference in new issue
Block a user