CVE-2015-10061 (published 2023-01-17T16:15Z)

A vulnerability was found in evandro-machado Trabalho-Web2. It has been classified as critical. This affects an unknown part of the file src/java/br/com/magazine/dao/ClienteDAO.java. The manipulation leads to sql injection. The patch is named f59ac954625d0a4f6d34f069a2e26686a7a20aeb. It is recommended to apply a patch to fix this issue. The associated identifier of this vulnerability is VDB-218427.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/evandro-machado/Trabalho-Web2
commit_details: repo_url: https://github.com/evandro-machado/Trabalho-Web2
author: Anonymous-pc
author_date: 2015-06-10 00:15:20-03:00
msg: ClienteDAO - alterados statements para utilizar o metodo setString do PreparedStatement para evitar SQL Injection
- alterados statements para utilizar ilike ao inves de like para pesquisar sem case sensitivity
BancoDeDados - colocado ponto e virgula apos todas as queries.
repository: repo_url: https://github.com/evandro-machado/Trabalho-Web2
repo_name: evandro-machado/Trabalho-Web2
description: Trabalho para aprovação na disciplina de Web2 e DAC
repo_language: Java
owner: evandro-machado
file_changes: filename: ClienteDAO.java
change_type: ModificationType.MODIFY
diff: @@ -32,9 +32,14 @@ public class ClienteDAO {
     private final String stmtRemoveCliente = "update Cliente set inativo = true where idCliente = ?";
 //    private final String stmtRemoveItemPedidoCliente = "delete from itempedido where idpedido = (select idpedido from pedido where idcliente = ?)";
 //    private final String stmtRemovePedidoCliente = "delete from pedido where idpedido = (select idpedido from pedido where idcliente= ? )";
-    private final String stmtBuscarNome = "select * from Cliente where nome like ";
-    private final String stmtBuscarCPF = "select * from Cliente where cpf like ";
-    private final String stmtBuscarEmail = "select * from Cliente where email like ";
+    private final String stmtBuscarNomeCliente = "select * from Cliente where nome ilike ? and perfil = 1 and inativo=false order by nome";
+    private final String stmtBuscarCPFCliente = "select * from Cliente where cpf ilike ? and perfil = 1 and inativo=false order by nome";
+    private final String stmtBuscarEmailCliente = "select * from Cliente where email ilike ? and perfil = 1 and inativo=false order by nome";
+    
+    private final String stmtBuscarNomeFuncionario = "select * from Cliente where nome ilike ? and perfil in (2,3) and inativo=false order by nome";
+    private final String stmtBuscarCPFFuncionario = "select * from Cliente where cpf ilike ? and perfil in (2,3) and inativo=false order by nome";
+    private final String stmtBuscarEmailFuncionario = "select * from Cliente where email ilike ? and perfil in (2,3) and inativo=false order by nome";
+    
     private final String stmtBuscarEmailExato = "select * from Cliente where email = ?";
 //    private final String stmtProcuraSobreNome = "select * from Cliente where sobrenome like ";
 //    private final String stmtProcuraCPF = "select * from Cliente where cpf like ";
@@ -270,7 +275,9 @@ public class ClienteDAO {
 
         try {
             con = ConnectionFactory.getConnection();
-            stmt = con.prepareStatement(stmtBuscarNome + "'%" + nome + "%' and (perfil = 2 or perfil = 3) and inativo=false order by nome");
+            nome = "%"+nome+"%";
+            stmt = con.prepareStatement(stmtBuscarNomeFuncionario);
+            stmt.setString(1,nome);
             rs = stmt.executeQuery();
             return montaListaClientes(rs);
 
@@ -302,7 +309,9 @@ public class ClienteDAO {
 
         try {
             con = ConnectionFactory.getConnection();
-            stmt = con.prepareStatement(stmtBuscarCPF + "'%" + cpf + "%' and (perfil = 2 or perfil = 3) and inativo=false order by nome");
+            cpf = "%"+cpf+"%";
+            stmt = con.prepareStatement(stmtBuscarCPFFuncionario);
+            stmt.setString(1, cpf);
             rs = stmt.executeQuery();
             return montaListaClientes(rs);
         } catch (SQLException e) {
@@ -333,7 +342,9 @@ public class ClienteDAO {
 
         try {
             con = ConnectionFactory.getConnection();
-            stmt = con.prepareStatement(stmtBuscarEmail + "'%" + email + "%' and (perfil = 2 or perfil = 3) and inativo=false order by nome");
+            email = "%"+email+"%";
+            stmt = con.prepareStatement(stmtBuscarEmailFuncionario);
+            stmt.setString(1,email);
             rs = stmt.executeQuery();
             return montaListaClientes(rs);
         } catch (SQLException e) {
@@ -363,7 +374,9 @@ public class ClienteDAO {
 
         try {
             con = ConnectionFactory.getConnection();
-            stmt = con.prepareStatement(stmtBuscarNome + "'%" + nome + "%' and perfil = 1 and inativo=false order by nome");
+            nome = "%"+nome+"%";
+            stmt = con.prepareStatement(stmtBuscarNomeCliente);
+            stmt.setString(1,nome);
             rs = stmt.executeQuery();
             return montaListaClientes(rs);
 
@@ -395,7 +408,9 @@ public class ClienteDAO {
 
         try {
             con = ConnectionFactory.getConnection();
-            stmt = con.prepareStatement(stmtBuscarCPF + "'%" + cpf + "%' and perfil = 1 and inativo=false order by nome");
+            cpf = "%"+cpf+"%";
+            stmt = con.prepareStatement(stmtBuscarCPFCliente);
+            stmt.setString(1, cpf);
             rs = stmt.executeQuery();
             return montaListaClientes(rs);
         } catch (SQLException e) {
@@ -426,7 +441,9 @@ public class ClienteDAO {
 
         try {
             con = ConnectionFactory.getConnection();
-            stmt = con.prepareStatement(stmtBuscarEmail + "'%" + email + "%' and perfil = 1 and inativo=false order by nome");
+            email = "%"+email+"%";
+            stmt = con.prepareStatement(stmtBuscarEmailCliente);
+            stmt.setString(1,email);
             rs = stmt.executeQuery();
             return montaListaClientes(rs);
         } catch (SQLException e) {

programming_language: Java
filename: BancoDeDados.sql
change_type: ModificationType.MODIFY
diff: @@ -52,7 +52,7 @@ idCliente int,
 valorTotal real,
 data DateTime,
 situacao int
-)
+);
 
 
 create table itemPedido(
@@ -61,4 +61,4 @@ idPedido int,
 irProduto int,
 quantidade int,
 valorUnitario int
-)
+);

programming_language: SQL