Back-End

17 jan, 2017

Verificando bugs de segurança com Maven + FindSecBugs

Publicidade

Hoje vamos deixar aqui um exemplo de como podemos configurar o Apache Maven para executar o plugin FindSecBugs em aplicações Java. Para exemplificar, vamos utilizar um projeto simples em SpringBoot que pode ser baixado aqui.

Depois de baixar, descompacte-o, navegue até a pasta complete e abra o pom.xml em seu editor favorito. O meu é o Atom.

Adicione o seguinte plugin:

<build>
  ...
    <plugins>
      ...
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>3.0.4</version>
            <configuration>
                <effort>Max</effort>
                <threshold>Medium</threshold> <!-- low é para auditores de seguranca -->
                <failOnError>true</failOnError>
                <includeFilterFile>src/main/resources/findbugs-security-include.xml</includeFilterFile>
                <excludeFilterFile>src/main/resources/findbugs-security-exclude.xml</excludeFilterFile>
                <plugins>
                    <plugin>
                        <groupId>com.h3xstream.findsecbugs</groupId>
                        <artifactId>findsecbugs-plugin</artifactId>
                        <version>LATEST</version> <!-- Auto-update to the latest stable -->
                    </plugin>
                </plugins>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
      ...
    </plugins>
  ...
</build>

Crie os dois arquivos abaixo:

– findbugs-security-include.xml:

<FindBugsFilter>
    <Match>
        <Bug category="SECURITY"/>
    </Match>
</FindBugsFilter>

– findbugs-security-exclude.xml:

<FindBugsFilter>
</FindBugsFilter>

Realize o build do projeto com mvn clean install e verifique o resultado.

[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) @ gs-serving-web-content ---
[INFO] 
[INFO] >>> findbugs-maven-plugin:3.0.4:check (default) > :findbugs @ gs-serving-web-content >>>
[INFO] 
[INFO] --- findbugs-maven-plugin:3.0.4:findbugs (findbugs) @ gs-serving-web-content ---
[INFO] Fork Value is true
[INFO] Done FindBugs Analysis....
[INFO] 
[INFO] <<< findbugs-maven-plugin:3.0.4:check (default) < :findbugs @ gs-serving-web-content <<<
[INFO] 
[INFO] --- findbugs-maven-plugin:3.0.4:check (default) @ gs-serving-web-content ---
[INFO] BugInstance size is 0
[INFO] Error size is 0
[INFO] No errors/warnings found
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ gs-serving-web-content ---

Para esta varredura e projeto não encontramos problemas de segurança, então, para intuito de testes vamos modificar a seguinte linha do pom.xml para Low e realizar um novo build:

<threshold>Low</threshold> <!-- low é para auditores de seguranca -->
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ gs-serving-web-content ---
[INFO] Building jar: /home/kleber/Downloads/gs-serving-web-content-master/complete/target/gs-serving-web-content-0.1.0.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) @ gs-serving-web-content ---
[INFO] 
[INFO] >>> findbugs-maven-plugin:3.0.4:check (default) > :findbugs @ gs-serving-web-content >>>
[INFO] 
[INFO] --- findbugs-maven-plugin:3.0.4:findbugs (findbugs) @ gs-serving-web-content ---
[INFO] Fork Value is true
     [java] Warnings generated: 1
[INFO] Done FindBugs Analysis....
[INFO] 
[INFO] <<< findbugs-maven-plugin:3.0.4:check (default) < :findbugs @ gs-serving-web-content <<<
[INFO] 
[INFO] --- findbugs-maven-plugin:3.0.4:check (default) @ gs-serving-web-content ---
[INFO] BugInstance size is 1
[INFO] Error size is 0
[INFO] Total bugs: 1
[INFO] hello.GreetingController is a Spring endpoint (Controller) [hello.GreetingController] At GreetingController.java:[lines 13-14] SPRING_ENDPOINT
[INFO] 
 
 
To see bug detail using the Findbugs GUI, use the following command "mvn findbugs:gui"

Bom, agora podemos ver o FindSecBugs encontrando um erro de segurança. Lembrando que este erro só é filtrado porque modificamos o threshold para Low, no controller hello.GreetingController categorizado como: SPRING_ENDPOINT, ok?!

Ficou alguma dúvida ou tem algum comentário? Fique à vontade nos campos abaixo!

Até a próxima.

***

Artigo publicado originalmente em: http://www.concretesolutions.com.br/2017/01/09/bugs-seguranca-maven-findsecbugs/