diff --git a/core/src/main/java/hudson/cli/CLIAction.java b/core/src/main/java/hudson/cli/CLIAction.java
index 70a458a653..9ea7dd795a 100644
--- a/core/src/main/java/hudson/cli/CLIAction.java
+++ b/core/src/main/java/hudson/cli/CLIAction.java
@@ -62,12 +62,11 @@ public class CLIAction implements UnprotectedRootAction, StaplerProxy {
}
public String getDisplayName() {
-
return "Jenkins CLI";
}
public String getUrlName() {
- return "cli";
+ return jenkins.CLI.DISABLED ? null : "cli";
}
public void doCommand(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
diff --git a/core/src/main/java/hudson/cli/CliProtocol.java b/core/src/main/java/hudson/cli/CliProtocol.java
index 99cdd172d1..7506f2f54c 100644
--- a/core/src/main/java/hudson/cli/CliProtocol.java
+++ b/core/src/main/java/hudson/cli/CliProtocol.java
@@ -32,7 +32,7 @@ public class CliProtocol extends AgentProtocol {
@Override
public String getName() {
- return "CLI-connect";
+ return jenkins.CLI.DISABLED ? null : "CLI-connect";
}
@Override
diff --git a/core/src/main/java/hudson/cli/CliProtocol2.java b/core/src/main/java/hudson/cli/CliProtocol2.java
index 1be9fff35b..8b5f2d96f3 100644
--- a/core/src/main/java/hudson/cli/CliProtocol2.java
+++ b/core/src/main/java/hudson/cli/CliProtocol2.java
@@ -24,7 +24,7 @@ import java.security.Signature;
public class CliProtocol2 extends CliProtocol {
@Override
public String getName() {
- return "CLI2-connect";
+ return jenkins.CLI.DISABLED ? null : "CLI2-connect";
}
@Override
diff --git a/core/src/main/java/jenkins/CLI.java b/core/src/main/java/jenkins/CLI.java
new file mode 100644
index 0000000000..970e59dc62
--- /dev/null
+++ b/core/src/main/java/jenkins/CLI.java
@@ -0,0 +1,17 @@
+package jenkins;
+
+import org.kohsuke.accmod.Restricted;
+import org.kohsuke.accmod.restrictions.NoExternalUse;
+
+/**
+ * Kill switch to disable the entire Jenkins CLI system.
+ *
+ * Marked as no external use because the CLI subsystem is nearing EOL.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+@Restricted(NoExternalUse.class)
+public class CLI {
+ // non-final to allow setting from $JENKINS_HOME/init.groovy.d
+ public static boolean DISABLED = Boolean.getBoolean(CLI.class.getName()+".disabled");
+}
diff --git a/test/pom.xml b/test/pom.xml
index fb89b44e9d..59883a3820 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -163,6 +163,21 @@ THE SOFTWARE.
mockito-core
test
+
+ org.reflections
+ reflections
+ 0.9.9
+
+
+ org.netbeans.modules
+ org-netbeans-insane
+ RELEASE72
+
+
+ com.github.stephenc.findbugs
+ findbugs-annotations
+ 1.3.9-1
+
org.codehaus.geb
geb-implicit-assertions
diff --git a/test/src/test/java/jenkins/CLITest.java b/test/src/test/java/jenkins/CLITest.java
new file mode 100644
index 0000000000..054d4df5a1
--- /dev/null
+++ b/test/src/test/java/jenkins/CLITest.java
@@ -0,0 +1,65 @@
+package jenkins;
+
+import hudson.cli.FullDuplexHttpStream;
+import hudson.model.Computer;
+import hudson.model.Failure;
+import hudson.remoting.Channel;
+import org.junit.Rule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+
+import java.io.FileNotFoundException;
+import java.net.URL;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public class CLITest {
+ @Rule
+ public JenkinsRule j = new JenkinsRule();
+
+ /**
+ * Checks if the kill switch works correctly
+ */
+ @Test
+ public void killSwitch() throws Exception {
+ // this should succeed, as a control case
+ makeHttpCall();
+ makeJnlpCall();
+
+ CLI.DISABLED = true;
+ try {
+ try {
+ makeHttpCall();
+ fail("Should have been rejected");
+ } catch (FileNotFoundException e) {
+ // attempt to make a call should fail
+ }
+ try {
+ makeJnlpCall();
+ fail("Should have been rejected");
+ } catch (Exception e) {
+ // attempt to make a call should fail
+ e.printStackTrace();
+
+ // the current expected failure mode is EOFException, though we don't really care how it fails
+ }
+ } finally {
+ CLI.DISABLED = false;
+ }
+ }
+
+ private void makeHttpCall() throws Exception {
+ FullDuplexHttpStream con = new FullDuplexHttpStream(new URL(j.getURL(), "cli"));
+ Channel ch = new Channel("test connection", Computer.threadPoolForRemoting, con.getInputStream(), con.getOutputStream());
+ ch.close();
+ }
+
+ private void makeJnlpCall() throws Exception {
+ int r = hudson.cli.CLI._main(new String[]{"-s",j.getURL().toString(), "version"});
+ if (r!=0)
+ throw new Failure("CLI failed");
+ }
+}
diff --git a/test/src/test/java/jenkins/security/Security218CliTest.java b/test/src/test/java/jenkins/security/Security218CliTest.java
index ae4cbeac4d..48b35b8363 100644
--- a/test/src/test/java/jenkins/security/Security218CliTest.java
+++ b/test/src/test/java/jenkins/security/Security218CliTest.java
@@ -32,6 +32,7 @@ import java.io.File;
import java.io.PrintStream;
import jenkins.security.security218.Payload;
import org.jenkinsci.remoting.RoleChecker;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
@@ -45,7 +46,14 @@ public class Security218CliTest {
@Rule
public JenkinsRule r = new JenkinsRule();
-
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeCommonsBeanutils1() throws Exception {
+ probe(Payload.CommonsBeanutils1, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
@PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
@Test
@Issue("SECURITY-218")
@@ -61,6 +69,41 @@ public class Security218CliTest {
// in newer commons-collections version => remoting implementation should filter this class anyway
probe(Payload.CommonsCollections2, PayloadCaller.EXIT_CODE_REJECTED);
}
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeCommonsCollections3() throws Exception {
+ probe(Payload.CommonsCollections3, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeCommonsCollections4() throws Exception {
+ probe(Payload.CommonsCollections4, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeCommonsCollections5() throws Exception {
+ probe(Payload.CommonsCollections5, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeCommonsCollections6() throws Exception {
+ probe(Payload.CommonsCollections6, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeFileUpload1() throws Exception {
+ probe(Payload.FileUpload1, -1);
+ }
@PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
@Test
@@ -68,6 +111,34 @@ public class Security218CliTest {
public void probeGroovy1() throws Exception {
probe(Payload.Groovy1, PayloadCaller.EXIT_CODE_REJECTED);
}
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeJdk7u21() throws Exception {
+ probe(Payload.Jdk7u21, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeJRMPClient() throws Exception {
+ probe(Payload.JRMPClient, PayloadCaller.EXIT_CODE_REJECTED);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeJRMPListener() throws Exception {
+ probe(Payload.JRMPListener, -1);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeJSON1() throws Exception {
+ probe(Payload.JSON1, PayloadCaller.EXIT_CODE_REJECTED);
+ }
//TODO: Fix the conversion layer (not urgent)
// There is an issue in the conversion layer after the migration to another XALAN namespace
@@ -76,7 +147,18 @@ public class Security218CliTest {
@Test
@Issue("SECURITY-218")
public void probeSpring1() throws Exception {
- probe(Payload.Spring1, 1);
+ // Reason it is -1 is that it is testing a test that is not in our version of Spring
+ // Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler
+ probe(Payload.Spring1, -1);
+ }
+
+ @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
+ @Test
+ @Issue("SECURITY-317")
+ public void probeSpring2() throws Exception {
+ // Reason it is -1 is that it is testing a test that is not in our version of Spring 4
+ // Caused by: java.lang.ClassNotFoundException: org.springframework.core.SerializableTypeWrapper$TypeProvider
+ probe(Payload.Spring2, -1);
}
private void probe(Payload payload, int expectedResultCode) throws Exception {
diff --git a/test/src/test/java/jenkins/security/security218/Payload.java b/test/src/test/java/jenkins/security/security218/Payload.java
index 43dc97a995..ea3c30b8ac 100644
--- a/test/src/test/java/jenkins/security/security218/Payload.java
+++ b/test/src/test/java/jenkins/security/security218/Payload.java
@@ -23,11 +23,8 @@
*/
package jenkins.security.security218;
-import jenkins.security.security218.ysoserial.payloads.CommonsCollections1;
-import jenkins.security.security218.ysoserial.payloads.CommonsCollections2;
-import jenkins.security.security218.ysoserial.payloads.Groovy1;
-import jenkins.security.security218.ysoserial.payloads.ObjectPayload;
-import jenkins.security.security218.ysoserial.payloads.Spring1;
+import jenkins.security.security218.ysoserial.payloads.*;
+import net.sf.json.JSON;
/**
@@ -35,10 +32,21 @@ import jenkins.security.security218.ysoserial.payloads.Spring1;
* @author Oleg Nenashev
*/
public enum Payload {
+ CommonsBeanutils1(CommonsBeanutils1.class),
CommonsCollections1(CommonsCollections1.class),
CommonsCollections2(CommonsCollections2.class),
+ CommonsCollections3(CommonsCollections3.class),
+ CommonsCollections4(CommonsCollections4.class),
+ CommonsCollections5(CommonsCollections5.class),
+ CommonsCollections6(CommonsCollections6.class),
+ FileUpload1(FileUpload1.class),
Groovy1(Groovy1.class),
- Spring1(Spring1.class);
+ Jdk7u21(Jdk7u21.class),
+ JRMPClient(JRMPClient.class),
+ JRMPListener(JRMPListener.class),
+ JSON1(JSON1.class),
+ Spring1(Spring1.class),
+ Spring2(Spring2.class);
private final Class extends ObjectPayload> payloadClass;
diff --git a/test/src/test/java/jenkins/security/security218/ysoserial/Deserializer.java b/test/src/test/java/jenkins/security/security218/ysoserial/Deserializer.java
new file mode 100755
index 0000000000..a74c904d79
--- /dev/null
+++ b/test/src/test/java/jenkins/security/security218/ysoserial/Deserializer.java
@@ -0,0 +1,58 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2013 Chris Frohoff
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package jenkins.security.security218.ysoserial;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.util.concurrent.Callable;
+
+public class Deserializer implements Callable