Add findsecbugs plugin to spotbugs.

And suppress existing warnings. We should clean some of them up, but that's for different PRs.
This commit is contained in:
Jeff Thompson committed 2020-01-23 14:53:53 -07:00
1 parent 30dbf728ec
commit c76ee59810
21 files changed
+63 -2

No files matched your search

+3
View File
@@ -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<String> 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;
}
@@ -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;
@@ -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();
@@ -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 {
}
+1 -1
View File
@@ -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<String> 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");
@@ -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());
+2
View File
@@ -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),
+2
View File
@@ -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");
@@ -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> 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()));
@@ -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<T> extends LargeText {
rsp.setContentType(isHtml() ? "text/html;charset=UTF-8" : "text/plain;charset=UTF-8");
}
@SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
private ConsoleAnnotator<T> createAnnotator(StaplerRequest req) throws IOException {
try {
String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null;
@@ -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<T> implements Serializable, Describable<Consol
*
* @return null if the encoded form is malformed.
*/
@SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException {
try {
byte[] preamble = new byte[PREAMBLE.length];
@@ -23,6 +23,8 @@
*/
package hudson.scheduler;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -51,7 +53,8 @@ public abstract class Hash {
* Produces an integer in [0,n)
*/
public abstract int next(int n);
@SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = "Not used for security.")
public static Hash from(String seed) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -23,6 +23,7 @@
*/
package hudson.security;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.User;
import jenkins.model.Jenkins;
import hudson.util.Scrambler;
@@ -97,6 +98,7 @@ public class BasicAuthenticationFilter implements Filter {
}
@SuppressWarnings("ACL.impersonate")
@SuppressFBWarnings(value = "UNVALIDATED_REDIRECT")
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
@@ -23,6 +23,7 @@
*/
package hudson.security;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Functions;
import com.google.common.base.Strings;
@@ -60,6 +61,7 @@ import java.text.MessageFormat;
*/
public class HudsonAuthenticationEntryPoint extends AuthenticationProcessingFilterEntryPoint {
@Override
@SuppressFBWarnings(value = "XSS_SERVLET")
public void commence(ServletRequest request, ServletResponse response, AuthenticationException reason) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
@@ -33,6 +33,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.util.Iterators.DuplicateFilterIterator;
/**
@@ -60,6 +61,7 @@ import hudson.util.Iterators.DuplicateFilterIterator;
* @author Kohsuke Kawaguchi
* @since 1.302
*/
@SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = "Not used for security.")
public class ConsistentHash<T> {
/**
* All the items in the hash, to their replication factors.
@@ -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) {
@@ -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;
@@ -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");
@@ -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) {
@@ -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();
+14
View File
@@ -407,6 +407,20 @@ THE SOFTWARE.
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<configuration>
<plugins>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>1.10.1</version>
</plugin>
</plugins>
<maxHeap>768</maxHeap>
</configuration>
</plugin>
</plugins>
</pluginManagement>