Groups | Blog | Home
all groups > dotnet ado.net > may 2007 >

dotnet ado.net : SQL Injections and parameterized SQL



Robert Simpson
5/30/2007 1:12:58 PM
In a parameterized query, the SQL statement with its parameter markers is
prepared, and then the parameters are pushed separately. The values inside
the parameters are not parsed by the SQL query parser, so there's nowhere in
the codepath for an injection to occur.

Robert


[quoted text, click to view]

LtyChan
5/30/2007 9:20:52 PM
This might be a stupid question - but can I be sure to avoid SQL injections
by using parameterized queries? Will SQL Server or ADO.NET kill any attempts
to drop or update data through sql injections (ei '; update ..... ;--), and
can see a log of any attempts somewhere (will SQL Server warn or fail)? Can
I read about what really happens when using parameterized queries
(SQLClient) somewhere?

Thanks

Miha Markic
5/30/2007 10:14:35 PM
Hi there,

[quoted text, click to view]

Yes. 100%.

Will SQL Server or ADO.NET kill any attempts
[quoted text, click to view]

SQL server will treat all parameter values as data and not as a part of sql
statement.

and
[quoted text, click to view]

No. SQL server (or any other database) doesn't care - it is all data from
SQL server perspective.

Can
[quoted text, click to view]

Parameter values are transfered separately from sql statement and are not
part of statement. Thus one can inject code into parameter values - ok, one
can inject code but the code won't be executed...

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
LtyChan
5/30/2007 10:33:41 PM
Thanks guys,

Parameterized queries it is then ;) (know that Store Procedures is better -
but i like to keep it in .net code)

Thanks

"Miha Markic" <miha at rthand com> skrev i en meddelelse
news:Ogdn1cvoHHA.3484@TK2MSFTNGP04.phx.gbl...
[quoted text, click to view]

William (Bill) Vaughn
5/31/2007 8:27:06 AM
As many have said, SQL injection is virtually impossible when using
parameterized queries. While I discuss this problem in my book I don't show
how to do it. There are sites and sessions that do so those that would want
to carry out data attacks can do so quite easily.
What was the meaning of the comment about SPs and keeping it in .NET?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

[quoted text, click to view]

AddThis Social Bookmark Button