sql injection - Parameterized SQL statements vs. very simple method -


when started write first sql-statements in programs felt quite comfortable protecting myself against sql-injection simple method colleague showed me. replaced single quotes 2 single quotes.

so example there searchfield in can enter customername search in customertable. if enter

peter's barbershop

the select statement like

select * customers customername = 'peter''s barbershop' 

if attacker insert this:

';drop table foo; -- 

the statement like:

select * customers customername = ''';drop table foo;--' 

it not drop table, search customertable customername ';drop table foo;-- which, suppose, won't found ;-)

now after while of writing statements , protecting myself against sql-injection method, read many developers use parameterized statements, never read article "our" method used. there reason it.

what scenarios parameterized statements cover our method doesn't? advantages of parameterized statements compared our method?

thanks
philipp

the parametrized queries has more proc defence sql-injection.

  1. it solves problem date & time formating & parsing.
  2. you can prepare execution plan parametrized query.
  3. the sql-injection protection.

i can't remember pros :).

however way "double every quotes" has problem fields limited character length.

for example:

  • the page has box "nickname" can 10 character long.
  • the user insert "don't care" - exact 10 characters.

now if double quotes, value has 11 characters , database "cut" it, , got value in db user typed.

so recommend parameters.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -