diff --git a/cli/src/main/java/hudson/cli/CLI.java b/cli/src/main/java/hudson/cli/CLI.java index 1b9b4856ad..4cf98e85c1 100644 --- a/cli/src/main/java/hudson/cli/CLI.java +++ b/cli/src/main/java/hudson/cli/CLI.java @@ -23,6 +23,7 @@ */ package hudson.cli; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.cli.client.Messages; import java.io.DataInputStream; import javax.net.ssl.HostnameVerifier; @@ -104,6 +105,7 @@ public class CLI { } private enum Mode {HTTP, SSH, WEB_SOCKET} + @SuppressFBWarnings(value = {"PATH_TRAVERSAL_IN", "URLCONNECTION_SSRF_FD"}, justification = "User provided values for running the program.") public static int _main(String[] _args) throws Exception { List args = Arrays.asList(_args); PrivateKeyProvider provider = new PrivateKeyProvider(); @@ -175,6 +177,7 @@ public class CLI { HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); // bypass host name check, too. HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { + @SuppressFBWarnings(value = "WEAK_HOSTNAME_VERIFIER", justification = "User set parameter to skip verifier.") public boolean verify(String s, SSLSession sslSession) { return true; } diff --git a/cli/src/main/java/hudson/cli/DiagnosedStreamCorruptionException.java b/cli/src/main/java/hudson/cli/DiagnosedStreamCorruptionException.java index 4708b425db..c7d3963f3b 100644 --- a/cli/src/main/java/hudson/cli/DiagnosedStreamCorruptionException.java +++ b/cli/src/main/java/hudson/cli/DiagnosedStreamCorruptionException.java @@ -1,5 +1,7 @@ package hudson.cli; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.io.PrintWriter; import java.io.StreamCorruptedException; import java.io.StringWriter; @@ -11,6 +13,7 @@ import java.io.StringWriter; * * @author Kohsuke Kawaguchi */ +@SuppressFBWarnings(value = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE") class DiagnosedStreamCorruptionException extends StreamCorruptedException { private final Exception diagnoseFailure; private final byte[] readBack; diff --git a/cli/src/main/java/hudson/cli/FullDuplexHttpStream.java b/cli/src/main/java/hudson/cli/FullDuplexHttpStream.java index 723e97f16c..1f066a620d 100644 --- a/cli/src/main/java/hudson/cli/FullDuplexHttpStream.java +++ b/cli/src/main/java/hudson/cli/FullDuplexHttpStream.java @@ -1,5 +1,7 @@ package hudson.cli; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -44,6 +46,7 @@ public class FullDuplexHttpStream { * @param authorization * The value of the authorization header, if non-null. */ + @SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "Client-side code doesn't involve SSRF.") public FullDuplexHttpStream(URL base, String relativeTarget, String authorization) throws IOException { if (!base.toString().endsWith("/")) { throw new IllegalArgumentException(base.toString()); @@ -93,6 +96,7 @@ public class FullDuplexHttpStream { } // As this transport mode is using POST, it is necessary to resolve possible redirections using GET first. + @SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "Client-side code doesn't involve SSRF.") private URL tryToResolveRedirects(URL base, String authorization) { try { HttpURLConnection con = (HttpURLConnection) base.openConnection(); diff --git a/cli/src/main/java/hudson/cli/NoCheckTrustManager.java b/cli/src/main/java/hudson/cli/NoCheckTrustManager.java index c69b3330c2..5a8346cb6e 100644 --- a/cli/src/main/java/hudson/cli/NoCheckTrustManager.java +++ b/cli/src/main/java/hudson/cli/NoCheckTrustManager.java @@ -1,5 +1,7 @@ package hudson.cli; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import javax.net.ssl.X509TrustManager; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; @@ -7,6 +9,7 @@ import java.security.cert.X509Certificate; /** * @author Kohsuke Kawaguchi */ +@SuppressFBWarnings(value = "WEAK_TRUST_MANAGER", justification = "User set parameter to skip verifier.") public class NoCheckTrustManager implements X509TrustManager { public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } diff --git a/cli/src/main/java/hudson/cli/SSHCLI.java b/cli/src/main/java/hudson/cli/SSHCLI.java index 39dc9210a3..cbfeea16b8 100644 --- a/cli/src/main/java/hudson/cli/SSHCLI.java +++ b/cli/src/main/java/hudson/cli/SSHCLI.java @@ -61,7 +61,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; */ class SSHCLI { - @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", justification = "Due to whatever reason FindBugs reports it fot try-with-resources") + @SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "Client-side code doesn't involve SSRF.") static int sshConnection(String jenkinsUrl, String user, List args, PrivateKeyProvider provider, final boolean strictHostKey) throws IOException { Logger.getLogger(SecurityUtils.class.getName()).setLevel(Level.WARNING); // suppress: BouncyCastle not registered, using the default JCE provider URL url = new URL(jenkinsUrl + "login"); diff --git a/core/src/main/java/hudson/ClassicPluginStrategy.java b/core/src/main/java/hudson/ClassicPluginStrategy.java index c5369614de..d426d36226 100644 --- a/core/src/main/java/hudson/ClassicPluginStrategy.java +++ b/core/src/main/java/hudson/ClassicPluginStrategy.java @@ -78,6 +78,7 @@ import java.util.logging.Logger; import static org.apache.commons.io.FilenameUtils.getBaseName; +@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "Admistrator action installing a plugin, which could do far worse.") public class ClassicPluginStrategy implements PluginStrategy { private static final Logger LOGGER = Logger.getLogger(ClassicPluginStrategy.class.getName()); diff --git a/core/src/main/java/hudson/Proc.java b/core/src/main/java/hudson/Proc.java index 6acb1ceeba..d134d0b8b7 100644 --- a/core/src/main/java/hudson/Proc.java +++ b/core/src/main/java/hudson/Proc.java @@ -23,6 +23,7 @@ */ package hudson; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Launcher.ProcStarter; import hudson.model.TaskListener; import hudson.remoting.Channel; @@ -215,6 +216,7 @@ public abstract class Proc { * @param err * null to redirect stderr to stdout. */ + @SuppressFBWarnings("COMMAND_INJECTION") public LocalProc(String[] cmd,String[] env,InputStream in,OutputStream out,OutputStream err,File workDir) throws IOException { this( calcName(cmd), stderr(environment(new ProcessBuilder(cmd),env).directory(workDir), err==null || err== SELFPUMP_OUTPUT), diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 7775b4ca6a..de29e9a013 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -596,6 +596,8 @@ public class Util { * @see DigestUtils#md5Hex(InputStream) */ @Nonnull + @SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = + "This method should only be used for non-security applications where their weakness is not a problem.") public static String getDigestOf(@Nonnull InputStream source) throws IOException { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); diff --git a/core/src/main/java/hudson/cli/Connection.java b/core/src/main/java/hudson/cli/Connection.java index 1961447778..a181c5d208 100644 --- a/core/src/main/java/hudson/cli/Connection.java +++ b/core/src/main/java/hudson/cli/Connection.java @@ -23,6 +23,7 @@ */ package hudson.cli; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.remoting.ClassFilter; import hudson.remoting.ObjectInputStreamEx; import hudson.remoting.SocketChannelStream; @@ -113,6 +114,7 @@ public class Connection { /** * Receives an object sent by {@link #writeObject(Object)} */ + @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION", justification = "Not used. We should just remove it.") public T readObject() throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStreamEx(in, getClass().getClassLoader(), ClassFilter.DEFAULT); @@ -192,6 +194,7 @@ public class Connection { * @return * A new {@link Connection} object that includes the transport encryption. */ + @SuppressFBWarnings(value = "STATIC_IV", justification = "Not used. We should just remove it.") public Connection encryptConnection(SecretKey sessionKey, String algorithm) throws IOException, GeneralSecurityException { Cipher cout = Cipher.getInstance(algorithm); cout.init(Cipher.ENCRYPT_MODE, sessionKey, new IvParameterSpec(sessionKey.getEncoded())); diff --git a/core/src/main/java/hudson/console/AnnotatedLargeText.java b/core/src/main/java/hudson/console/AnnotatedLargeText.java index c862d0c61b..278c32c9a1 100644 --- a/core/src/main/java/hudson/console/AnnotatedLargeText.java +++ b/core/src/main/java/hudson/console/AnnotatedLargeText.java @@ -25,6 +25,7 @@ */ package hudson.console; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import jenkins.model.Jenkins; import hudson.remoting.ObjectInputStreamEx; import java.util.concurrent.TimeUnit; @@ -116,6 +117,7 @@ public class AnnotatedLargeText extends LargeText { rsp.setContentType(isHtml() ? "text/html;charset=UTF-8" : "text/plain;charset=UTF-8"); } + @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION") private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException { try { String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null; diff --git a/core/src/main/java/hudson/console/ConsoleNote.java b/core/src/main/java/hudson/console/ConsoleNote.java index 4d2e2c2530..c8dd1675fe 100644 --- a/core/src/main/java/hudson/console/ConsoleNote.java +++ b/core/src/main/java/hudson/console/ConsoleNote.java @@ -23,6 +23,7 @@ */ package hudson.console; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.ExtensionPoint; import hudson.Functions; import hudson.MarkupText; @@ -232,6 +233,7 @@ public abstract class ConsoleNote implements Serializable, Describable { /** * All the items in the hash, to their replication factors. diff --git a/core/src/main/java/hudson/util/DOSToUnixPathHelper.java b/core/src/main/java/hudson/util/DOSToUnixPathHelper.java index afe949c8db..ab49acb693 100644 --- a/core/src/main/java/hudson/util/DOSToUnixPathHelper.java +++ b/core/src/main/java/hudson/util/DOSToUnixPathHelper.java @@ -1,5 +1,6 @@ package hudson.util; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.EnvVars; import hudson.Util; import org.kohsuke.accmod.Restricted; @@ -16,6 +17,7 @@ class DOSToUnixPathHelper { void error(String string); void validate(File fexe); } + @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN") static private boolean checkPrefix(String prefix, Helper helper) { File f = new File(prefix); if(f.exists()) { @@ -30,6 +32,7 @@ class DOSToUnixPathHelper { } return false; } + @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN") static void iteratePath(String exe, Helper helper) { exe = fixEmpty(exe); if(exe==null) { diff --git a/core/src/main/java/hudson/util/FormFieldValidator.java b/core/src/main/java/hudson/util/FormFieldValidator.java index 292d5d1141..09f9955655 100644 --- a/core/src/main/java/hudson/util/FormFieldValidator.java +++ b/core/src/main/java/hudson/util/FormFieldValidator.java @@ -23,6 +23,7 @@ */ package hudson.util; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.FilePath; import hudson.ProxyConfiguration; import hudson.Util; @@ -145,6 +146,7 @@ public abstract class FormFieldValidator { /** * Gets the parameter as a file. */ + @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "Not used.") protected final File getFileParameter(String paramName) { return new File(Util.fixNull(request.getParameter(paramName))); } @@ -318,6 +320,7 @@ public abstract class FormFieldValidator { super(request, response); } + @SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD") protected void check() throws IOException, ServletException { String value = fixEmpty(request.getParameter("value")); if(value==null) {// nothing entered yet @@ -513,6 +516,7 @@ public abstract class FormFieldValidator { super(request, response, true); } + @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "Not used.") protected void check() throws IOException, ServletException { String exe = fixEmpty(request.getParameter("value")); FormFieldValidator.Executable self = this; diff --git a/core/src/main/java/jenkins/model/RunIdMigrator.java b/core/src/main/java/jenkins/model/RunIdMigrator.java index 4af582072e..69406c0292 100644 --- a/core/src/main/java/jenkins/model/RunIdMigrator.java +++ b/core/src/main/java/jenkins/model/RunIdMigrator.java @@ -24,6 +24,7 @@ package jenkins.model; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; import hudson.Util; import hudson.model.Job; @@ -309,6 +310,7 @@ public final class RunIdMigrator { * Reverses the migration, in case you want to revert to the older format. * @param args one parameter, {@code $JENKINS_HOME} */ + @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "Only used as an command-line process.") public static void main(String... args) throws Exception { if (args.length != 1) { throw new Exception("pass one parameter, $JENKINS_HOME"); diff --git a/core/src/main/java/jenkins/model/identity/IdentityRootAction.java b/core/src/main/java/jenkins/model/identity/IdentityRootAction.java index 1ea465ec07..d83cb88ef7 100644 --- a/core/src/main/java/jenkins/model/identity/IdentityRootAction.java +++ b/core/src/main/java/jenkins/model/identity/IdentityRootAction.java @@ -1,5 +1,6 @@ package jenkins.model.identity; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; import hudson.model.UnprotectedRootAction; import java.security.MessageDigest; @@ -61,6 +62,7 @@ public class IdentityRootAction implements UnprotectedRootAction { * * @return the fingerprint of the public key. */ + @SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = "Not used for security. ") public String getFingerprint() { RSAPublicKey key = InstanceIdentityProvider.RSA.getPublicKey(); if (key == null) { diff --git a/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol4.java b/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol4.java index e1d85d782b..8e3f595999 100644 --- a/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol4.java +++ b/core/src/main/java/jenkins/slaves/JnlpSlaveAgentProtocol4.java @@ -23,6 +23,7 @@ */ package jenkins.slaves; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; import hudson.ExtensionList; import hudson.model.Computer; @@ -98,6 +99,7 @@ public class JnlpSlaveAgentProtocol4 extends AgentProtocol { * @throws KeyManagementException if things go wrong. * @throws IOException if things go wrong. */ + @SuppressFBWarnings("HARD_CODE_PASSWORD") public JnlpSlaveAgentProtocol4() throws KeyStoreException, KeyManagementException, IOException { // prepare our local identity and certificate X509Certificate identityCertificate = InstanceIdentityProvider.RSA.getCertificate(); diff --git a/pom.xml b/pom.xml index b26f01f57d..24a7fdfac5 100755 --- a/pom.xml +++ b/pom.xml @@ -407,6 +407,20 @@ THE SOFTWARE. org.codehaus.mojo animal-sniffer-maven-plugin + + com.github.spotbugs + spotbugs-maven-plugin + + + + com.h3xstream.findsecbugs + findsecbugs-plugin + 1.10.1 + + + 768 + +