Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid SQL injection attacks in my ASP.NET application?

Tags:

I need to avoid being vulnerable to SQL injection in my ASP.NET application. How might I accomplish this?

like image 683
balaweblog Avatar asked Nov 20 '08 11:11

balaweblog


People also ask

How can SQL injection attacks be prevented?

The only sure way to prevent SQL Injection attacks is input validation and parametrized queries including prepared statements. The application code should never use the input directly. The developer must sanitize all input, not only web form inputs such as login forms.

Is ASP Net vulnerable to SQL injection?

No, ASP.Net does not protect against SQL Injections.

How SQL injection attack can be prevented explain with the help of C# code?

The use of a Web Application Firewall for web applications that access databases can help identify SQL injection attempts and may help prevent SQL injection attempts from reaching the application. Another safety precaution would be to encrypt passwords in the database.

What is SQL injection attack in C#?

SQL injection is an attack in which malicious code is inserted into strings that are later passed to an instance of SQL Server for parsing and execution.


1 Answers

Even though your question is very generic, a few rules always apply:

  • Use parameterized queries (SqlCommand with SqlParameter) and put user input into parameters.
  • Don't build SQL strings out of unchecked user input.
  • Don't assume you can build a sanitizing routine that can check user input for every kind of malformedness. Edge cases are easily forgotten. Checking numeric input may be simple enough to get you on the safe side, but for string input just use parameters.
  • Check for second-level vulnerabilites - don't build SQL query strings out of SQL table values if these values consist of user input.
  • Use stored procedures to encapsulate database operations.
like image 181
Tomalak Avatar answered Sep 30 '22 17:09

Tomalak