private void CheckSqlInjection(string query, IDbLog log) { if (checkQuery(query)) { bool ok = true; // no permitir comentarios ni algunas instrucciones maliciosas if (query.IndexOf("--") > -1) { log.end(null, "No se admiten comentarios de SQL en la cadena de selección\n" + this.rutaDDBB); throw new ArgumentException("No se admiten comentarios de SQL en la cadena de selección. SQL: " + query); } else if (query.ToUpper().IndexOf("DROP TABLE ") > -1) { log.end(null, "La cadena debe ser SELECT campos FROM tabla, no DROP y otros comandos no adecuados...\n" + this.rutaDDBB); throw new ArgumentException("La cadena debe ser SELECT campos FROM tabla, no DROP y otros comandos no adecuados... SQL: " + query); } else if (query.ToUpper().IndexOf("DROP PROCEDURE ") > -1) { log.end(null, "La cadena debe ser SELECT campos FROM tabla, no DROP y otros comandos no adecuados...\n" + this.rutaDDBB); throw new ArgumentException("La cadena debe ser SELECT campos FROM tabla, no DROP y otros comandos no adecuados... SQL: " + query); } else if (query.ToUpper().IndexOf("DROP FUNCTION ") > -1) { log.end(null, "La cadena debe ser SELECT campos FROM tabla, no DROP y otros comandos no adecuados...\n" + this.rutaDDBB); throw new ArgumentException("La cadena debe ser SELECT campos FROM tabla, no DROP y otros comandos no adecuados... SQL: " + query); } else { ok = true; } // Comprobar que realmente se use SELECT, o EXEC if (query.ToUpper().IndexOf("EXEC") < 0) { ok = false; } // Comprobar que realmente se use SELECT, o EXEC if (query.ToUpper().IndexOf("SELECT") < 0 && ok == false) { log.end(null, "La cadena debe ser SELECT campos FROM tabla / EXEC Storage Proces and variables\n" + this.rutaDDBB); throw new ArgumentException("Query must be SELECT fields FROM table / EXEC Storage Process and variables. SQL: " + query); } else { log.end(null, "Ha superado la prueba de comando correcto.\n" + this.rutaDDBB); } } else { log.end(null, "No ha superado la prueba de comando correcto.\n" + this.rutaDDBB); throw new ArgumentException("Query must be SELECT fields FROM table / EXEC Storage Process and variables. SQL: " + query); } }