c# - Why does using parameterized queries or entity framework prevent sql injection? -


I have a good understanding of SQL injection. This is when a SQL query that should be something like a customer from

  SELECT FirstName, LastName. Customer customer WHERE customer ID = @valueFromApplication   

changes like a query select first name, last name from customers WHERE CustomerId = ''; Drop Account Foo -

Whenever users enter anything malicious in your app, website, customer .. I also know that we can only try to leave the attacker. To find the names of tables and get information from them.

I also have a few things that help in preventing it:

  1. Using stored procedures that take parameters (SQL Server
  2. parametric Using SQL queries
  3. Using LINQ for entity framework / unit (C #, probably F #?)

    How can these things really be stopped? Having SQL injection? Why not the attacker only the malicious value that whatever the input is before Using and using the same result can pass.

    Your first example is parameter And is not insecure against SQL injection.

    Parameter-related questions are not replaced with values ​​only by the server (as you can manually replace @var With value ). They are sent and received as you It has been sent .. with @valueFromApplication .

    The server will parse the query. And when it becomes a variable, then this value will be supplied if it is the value Then ''; Drop Database Foo - .. then it becomes Value . It does not parse it. It uses only text / number / whatever type.

    To add an entity framework, it uses internally paramized queries, so it is also Secure SQL injection.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -