diff --git a/core/src/main/java/hudson/security/HudsonFilter.java b/core/src/main/java/hudson/security/HudsonFilter.java index 40c7e7c69d..e59e9d4e7e 100644 --- a/core/src/main/java/hudson/security/HudsonFilter.java +++ b/core/src/main/java/hudson/security/HudsonFilter.java @@ -36,6 +36,7 @@ import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; import org.acegisecurity.AuthenticationManager; import org.acegisecurity.ui.rememberme.RememberMeServices; @@ -153,7 +154,10 @@ public class HudsonFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { LOGGER.entering(HudsonFilter.class.getName(), "doFilter"); - + + // this is not the best place to do it, but doing it here makes the patch smaller. + ((HttpServletResponse)response).setHeader("X-Content-Type-Options", "nosniff"); + // to deal with concurrency, we need to capture the object. Filter f = filter; diff --git a/core/src/main/java/hudson/util/FormValidation.java b/core/src/main/java/hudson/util/FormValidation.java index 12b6c069d2..ac471cb958 100644 --- a/core/src/main/java/hudson/util/FormValidation.java +++ b/core/src/main/java/hudson/util/FormValidation.java @@ -199,7 +199,7 @@ public abstract class FormValidation extends IOException implements HttpResponse " " + Messages.FormValidation_Error_Details() + "
"
-            + Functions.printThrowable(e) +
+            + Util.escape(Functions.printThrowable(e)) +
             "
",kind ); } diff --git a/core/src/main/java/jenkins/security/ApiTokenProperty.java b/core/src/main/java/jenkins/security/ApiTokenProperty.java index caa9ed8853..124d8bd78f 100644 --- a/core/src/main/java/jenkins/security/ApiTokenProperty.java +++ b/core/src/main/java/jenkins/security/ApiTokenProperty.java @@ -81,6 +81,7 @@ public class ApiTokenProperty extends UserProperty { } public void changeApiToken() throws IOException { + user.checkPermission(Jenkins.ADMINISTER); _changeApiToken(); if (user!=null) user.save(); diff --git a/core/src/test/java/hudson/util/FormValidationTest.java b/core/src/test/java/hudson/util/FormValidationTest.java index 7f22a1371e..717d1768f4 100644 --- a/core/src/test/java/hudson/util/FormValidationTest.java +++ b/core/src/test/java/hudson/util/FormValidationTest.java @@ -28,6 +28,9 @@ import static org.junit.Assert.*; import java.util.Arrays; import org.junit.Test; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author sogabe @@ -105,4 +108,10 @@ public class FormValidationTest { private FormValidation aggregate(FormValidation... fvs) { return FormValidation.aggregate(Arrays.asList(fvs)); } + + @Test + public void formValidationException() { + FormValidation fv = FormValidation.error(new Exception("