3
I have an internal method that is called on the basis of another query, it is this way down. I wonder if this would be a "string.Format" error, if it would be possible to send an Injection SQL?
public BuscaProdutosDermaClubeEntity ProdutoDermaClube(string codigoproduto)
{
var strQuery = "";
strQuery += " Usp_Site_BuscaProdutosDermaClub";
strQuery += string.Format(" @codigoproduto = '{0}' ", codigoproduto);
using (contexto = new Contexto())
{
var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
return TransformaReaderEmListaObjetos(retornoDataReader).FirstOrDefault();
}
}
public SqlDataReader ExecutaComandoComRetorno(string strQuery)
{
var cmdComando = new SqlCommand(strQuery, minhaConexao);
return cmdComando.ExecuteReader();
}
In the database Procedure has a variable @codigoproduto char(20), if it is an error, which is the best correction?
Is a
StoredProcedure
? because it passes the value so if it isStoredProcedure
if there is an ideal and correct way? what is insideExecutaComandoComRetorno
he treats the data?– novic
adjusted the question
– Harry
Yes has problems your code in security and other...
– novic
Complementing what has already been said: Besides using Parameters defining its query in an "immutable" way in its construction and use, validate the inputs and outputs, following the idea of "Least Privilege", giving the user only the necessary for that context. An example is a field that has the purpose of receiving only literal characters, why receive special characters? Or even if you need to, validate possible malicious entries. - https://www.owasp.org/index.php/Least_privilege
– G. M4rc14L