Comment On SQL Injection Prevention 101

Louis' organization has some pretty standard coding policies. Two key policies are that database access is allowed only via stored procedures and that all code must be reviewed before being deployed to the testing environment. There's no exception to this, meaning that everyone's code, even the highly-paid consultants' code, must go through review. One of the senior consultants on the team recently submitted this code for review ... [expand full text]
« PrevPage 1 | Page 2Next »

Re: SQL Injection Prevention 101

2005-08-18 14:24 • by El Duderino

Seems that his whole life is an "Oh Duh" moment.


Senior Consultant?!  The fanciest resume in the world apparently can replace ability and experience. Go figure.

Re: SQL Injection Prevention 101

2005-08-18 14:26 • by richleick
Well, duh!  He is obviously still missing a lot:



CREATE PROCEDURE [SADynamicTPSBuilder]
(
@SELECTS VARCHAR(8000),
@JOINS VARCHAR(8000)
@WHERES VARCHAR(8000)
@ORDERS VARCHAR(8000)
) AS
BEGIN

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

EXEC
(@SELECTS + @JOINS + @WHERES + @ORDERS)

RETURN(-1)

END

I mean seriously, what's the point if I can't specify my where and order by clause.



"I sense the sarcasm."

"Good because I'm laying it on pretty thick."

Re: SQL Injection Prevention 101

2005-08-18 14:35 • by Ytram
I get it.  -1 is a magic number and constants should be used.  Geez, what an idiot.

Re: SQL Injection Prevention 101

2005-08-18 14:36 • by dubwai
Uh, why would a mere full-time employee review a consultant's code?  That makes no sense.  All consultants are super-geniuses.  That's why they charge such high hourly-rates.  That's the way we do it where we work.  For example, we paid contractors two million dollars to write a system.  They just stopped working on it after 2 years.  Here's the best part.  It doesn't work at all.  This saves the company a lot of money in the long-run because there's no maintainance cost.

Re: SQL Injection Prevention 101

2005-08-18 14:39 • by Matt
41160 in reply to 41156
I think they rejected it because he didn't use sp_executesql.



Re: SQL Injection Prevention 101

2005-08-18 14:42 • by Maurits
41161 in reply to 41160
Why do I think the next iteration will involve xp_readmail...

Re: SQL Injection Prevention 101

2005-08-18 14:43 • by Ytram
41162 in reply to 41159
dubwai:
Uh, why would a mere full-time
employee review a consultant's code?  That makes no
sense.  All consultants are super-geniuses.  That's why they
charge such high hourly-rates.  That's the way we do it where we
work.  For example, we paid contractors two million dollars to
write a system.  They just stopped working on it after 2
years.  Here's the best part.  It doesn't work at all.  This saves the company a lot of money in the long-run because there's no maintainance cost.




Man, that makes me want to make a consulting company.  Think of
all the seemingly impossible promises you can make to your clients:



"I guarantee you that you will not need to invest valuable time maintaining the software we produce for you" (your example)



"After we're done producing software for you, you'll never need us for anything ever again!"



"The software we'll produce will not put any kind of strain whatsoever on your servers or network."



"Our software is guaranteed to work as intended."

Re: SQL Injection Prevention 101

2005-08-18 14:49 • by dubwai
41163 in reply to 41162

Ytram:
dubwai:
Uh, why would a mere full-time employee review a consultant's code?  That makes no sense.  All consultants are super-geniuses.  That's why they charge such high hourly-rates.  That's the way we do it where we work.  For example, we paid contractors two million dollars to write a system.  They just stopped working on it after 2 years.  Here's the best part.  It doesn't work at all.  This saves the company a lot of money in the long-run because there's no maintainance cost.


Man, that makes me want to make a consulting company.  Think of all the seemingly impossible promises you can make to your clients:


Well, they had already produced code that sort of worked or worked with a babysitter and a lot of prodding.  But they finally got some kids right out of college and built the ultimate in software.  As you say, it uses no resources and costs nothing to maintain.  you can understand why we are expanding the use of contractors.  We want to see if other companies can produce this type of high-caliber software.

Re: SQL Injection Prevention 101

2005-08-18 14:50 • by titltn21

Man do I love SQL WTFs !!!


Perhaps the next attempt will involve


STEP 1: Inserting the SQL statement into some SQLLibrary table


STEP 2: Present a stored proc that retrieves the SQL statement from SQLLibrary by a passed ID and executes the retrieved SQL string


bye bye SQL Injection .. really ...


 


CREATE PROCEDURE [DynamicTPSBuilder]
(
  @SQLID INT
) AS
BEGIN


  SET NOCOUNT ON
  SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED


  DECLARE @SQL VARCHAR(8000)
  --Get SQL
  SELECT @SQL = SQLString FROM SQLLibrary WHERE SQLID = @SQLID
  --Exec SQL
  EXEC (@SQL)


  RETURN(-1)


END

Re: SQL Injection Prevention 101

2005-08-18 14:53 • by Mung Kee
Alex Papadimoulis:


CREATE PROCEDURE [SADynamicTPSBuilder]
(
@SELECTS VARCHAR(8000),
@JOINS VARCHAR(8000)
) AS
BEGIN

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

EXEC
(@SELECTS + @JOINS)

RETURN(-1)

END




The only thing he did was allow a 16k character sql statement instead
of 8k.  He/she must be one of those dot com throwbacks who got
into it for the money but shouldn't even be out of the house without
their hickey helmet...let alone programming.  I thought they all
went back to their hr/marketing/landscaping/etc. jobs by now.

Re: SQL Injection Prevention 101

2005-08-18 15:07 • by Rick
41167 in reply to 41163
One point to consider though with this is that I've been to Security
presentations where they said if you used parameterized stored
procedures you would protect yourself from SQL Injection attacks. That
is obviously not the case here. So make sure you take necessary steps
like a regex against the input strings to check for Sql Injection
anyways.

Re: SQL Injection Prevention 101

2005-08-18 15:10 • by Free

Its for TPS Reports, no-one is gonna call that from outside so its ok right :P


 


 

Re: SQL Injection Prevention 101

2005-08-18 15:11 • by coder
41169 in reply to 41165
titltn21:

Man do I love SQL WTFs !!!


Perhaps the next attempt will involve


STEP 1: Inserting the SQL statement into some SQLLibrary table


STEP 2: Present a stored proc that retrieves the SQL statement from SQLLibrary by a passed ID and executes the retrieved SQL string


bye bye SQL Injection .. really ...


 


CREATE PROCEDURE [DynamicTPSBuilder]
(
  @SQLID INT
) AS
BEGIN


  SET NOCOUNT ON
  SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED


  DECLARE @SQL VARCHAR(8000)
  --Get SQL
  SELECT @SQL = SQLString FROM SQLLibrary WHERE SQLID = @SQLID
  --Exec SQL
  EXEC (@SQL)


  RETURN(-1)


END



I worked for a company where that was pretty standard practice. Of course it wasn't for web ASP applications, but rather for SQL batch jobs. And no Return(-1) at the end.

Re: SQL Injection Prevention 101

2005-08-18 15:12 • by Maurits
41170 in reply to 41167
Anonymous:
One point to consider though with this is that I've been to Security
presentations where they said if you used parameterized stored
procedures you would protect yourself from SQL Injection attacks. That
is obviously not the case here. So make sure you take necessary steps
like a regex against the input strings to check for Sql Injection
anyways.


Any time you execute dynamically-built SQL, you have to look out for a SQL injection possibility.

This applies to client-to-server calls where SQL is passed to a SQL engine... as the parameterized stored procedure sentence above indicates...

But it ALSO applies to dynamically built SQL within a stored procedure.  Any time you use EXEC or sp_executesql or any of their cousins, you have to stop and consider the possibility of injection.

Usually all you need is a simple Replace(., '''', '''''') to fix things.  And usually you only need that for character-type parameters.

But watch out for things like EXECUTE SearchSomething... @OrderBy = 'ID DESC'

Re: SQL Injection Prevention 101

2005-08-18 15:12 • by Str8Dog
41171 in reply to 41166
Mung Kee:



The only thing he did was allow a 16k character sql statement instead
of 8k.  He/she must be one of those dot com throwbacks who got
into it for the money but shouldn't even be out of the house without
their hickey helmet...let alone programming.  I thought they all
went back to their hr/marketing/landscaping/etc. jobs by now.




sign me up for hickey helmet please.

Re: SQL Injection Prevention 101

2005-08-18 15:16 • by johnl
41172 in reply to 41169

Hang on....  This is really freaky.  A couple of weeks ago, we discovered a veritable dearth of READ UNCOMMITED statements in our stored procedure (that's worth a chortle all on its own), and yesterday I was discussing SQL injection with a colleague of mine, and how it would affect our planned buctracking/knowledge base system if we allowed free text searches.


 


Spooky, or what?

Re: SQL Injection Prevention 101

2005-08-18 15:32 • by A Wizard A True Star

Oh, I know what the WTF is. They should have called it sp_SADynamicTPSBuilder, of course.


But, seriously...


That EXEC(sql string) function might possibly be the worst idea ever thought of in the entire history of MS SQL Server. If you really really need your SQL to be that dynamic (and I would contend there's absolutely no reason you should) then at least build your strings in the ASP or VB code.


 

Re: SQL Injection Prevention 101

2005-08-18 15:36 • by Maurits
41177 in reply to 41166
Mung Kee:
The only thing he did was allow a 16k character sql statement instead
of 8k.


Does that really work?  (Tries it...) wow, it works...

declare @a varchar(8000)
declare @b varchar(8000)

declare @prefix varchar(500)
declare @postfix varchar(500)

select @prefix = 'select datalength('''
select @postfix = ''')'

select @a = @prefix + replicate('a', 8000 - len(@prefix))
select @b = replicate('b', 8000 - len(@postfix)) + @postfix

exec (@a + @b)
-- result: 15979

Re: SQL Injection Prevention 101

2005-08-18 15:37 • by Mung Kee
41178 in reply to 41171
Str8Dog:
Mung Kee:



The only thing he did was allow a 16k character sql statement instead
of 8k.  He/she must be one of those dot com throwbacks who got
into it for the money but shouldn't even be out of the house without
their hickey helmet...let alone programming.  I thought they all
went back to their hr/marketing/landscaping/etc. jobs by now.




sign me up for hickey helmet please.


doh!  I forgot to put mine on this AM.

Re: SQL Injection Prevention 101

2005-08-18 15:43 • by diaphanein
41179 in reply to 41154
El Duderino:

Seems that his whole life is an "Oh Duh" moment.



Probably his parents', too.

Re: SQL Injection Prevention 101

2005-08-18 16:49 • by RayS
Home Security Guy has a meetiing with this SQL Consultant:



HSG: You know, if you leave your door open like that someone will steal your car.

SQLC: .......

HSG: Ummm... someone can get in the door, and steal the car.

SQLC: ..... oh, I get it.



(5 minutes later)



SQLCL: Right, I went back to my office and closed the doo.... huh, where's my car gone?

Re: SQL Injection Prevention 101

2005-08-18 17:15 • by Eric
41190 in reply to 41181

He didn't get the memo about the TPS reports...  [:D]

Re: SQL Injection Prevention 101

2005-08-18 17:23 • by hank miller
Wtf?   Code reviews?   Worried about injection
attacks?  What universe does Louis work in?  I want to
switch.  Don't they know that code review is something to pay lip
service to, but is too hard to actually do?  The few times I've
seen it, I've had to force
it down their throats. 



Here, fresh out of school, and I wrote this code, will you review it
and tell me if I'm doing ok?   "Looks like code written in
our language and it seems like it will compile - commit it."
   Come to think of it, those guys quit a few months latter,
and I ended up maintaining their code - it would have been sent here
if this site existed back then.









Re: SQL Injection Prevention 101

2005-08-18 17:29 • by mm

Allowing only stored procedure access to a database is a huge WTF and should only be favored by psycho DBAs.  It's like the cops fighting speeders by making everyone take the bus.  Then only the bus drivers can speed.  Just try and implement a sensible caching or object relational mapping strategy when you are in this scenario...there are lots of ways to prevent SQL injection attacks.  Allowing only stored procedures is not one on its own, as this case proves.  Who is to say that the consultant wasn't filtering for SQL injection attacks on the code that invoked the stored procedure?


 

Re: SQL Injection Prevention 101

2005-08-18 17:55 • by dubwai
41198 in reply to 41194
Anonymous:

Allowing only stored procedure access to a database is a huge WTF and should only be favored by psycho DBAs.  It's like the cops fighting speeders by making everyone take the bus.  Then only the bus drivers can speed.



Yeah, I mean, it's just like have a controlled production environment.  WTF, why shouldn't anybody be able to go and do whatever they please.  Encapsulation, that's stupid too.


Anonymous:


Just try and implement a sensible caching or object relational mapping strategy when you are in this scenario...



Huh?  Why would that be a problem?  Stored procedures are just as relational as any other type of SQL.


Anonymous:


there are lots of ways to prevent SQL injection attacks.  Allowing only stored procedures is not one on its own, as this case proves. 



Again, huh?  The WTF is that the person was executing a statement outside of a stored procedure.  If the developer only called a stored procedure, he wouldn't be able to create one.  How do you create a SQL injection attack if all you do is call stored procedures?


Anonymous:


Who is to say that the consultant wasn't filtering for SQL injection attacks on the code that invoked the stored procedure?



That the consultant wasn't aware of them is a big clue.  And why reinvent the wheel?


A stored procdure is a great way to create clean interfaces between code and the DB.  It's a lot easier to refactor code to call the same stored procedure in a new DB than to refactor all the SQL in your code.  In Java, for example, it's just a matter of changing drivers to switch DB vendors if you only use stored procedures.  It also insulates the code from table structure changes.

Re: SQL Injection Prevention 101

2005-08-18 18:08 • by Sean Connery
41199 in reply to 41172
johnl:

...and how it would affect our planned buctracking/knowledge base system if we allowed free text searches.





Oh man. One typo away from butcracking.

Re: SQL Injection Prevention 101

2005-08-18 18:39 • by evnafets

Obviously the WTF is that he included no exception handling in the stored procedure.
This code needs to be added to the end:

EXCEPTION
  WHEN others 
  THEN
    NULL;
[8-)]

Re: SQL Injection Prevention 101

2005-08-18 18:54 • by Arachnid
41201 in reply to 41162
"Buy a car from us and you'll never go anywhere else again!"

Re: SQL Injection Prevention 101

2005-08-18 19:11 • by tiro
This is not a rhetorical question. 



How could anyone possible think that this would fix sql injection problems?

Re: SQL Injection Prevention 101

2005-08-18 20:08 • by Mung Kee
41205 in reply to 41199
Sean Connery:
johnl:

...and how it would affect our planned buctracking/knowledge base system if we allowed free text searches.





Oh man. One typo away from butcracking.




Sean Connery: "I'll take Anal Bum Cover for 7000."

Trebek: "That's An Album Cover."

Re: SQL Injection Prevention 101

2005-08-18 20:20 • by pagh
41206 in reply to 41166

The only thing he did was allow a 16k character sql statement instead of 8k.


Actually, not even that. If the database in question has an 8000 character limit on the varchars, as is quite likely, then concatenating two big strings that add up to over 8000 characters will truncate. So this is *even dumber* than it first appears.

Re: SQL Injection Prevention 101

2005-08-18 20:21 • by monkey@thekeyboard
41207 in reply to 41159

dubwai:
For example, we paid contractors two million dollars to write a system.  They just stopped working on it after 2 years.  Here's the best part.  It doesn't work at all.  This saves the company a lot of money in the long-run because there's no maintainance cost.


 


I've seen that scenario in the double-digit millions a couple times now. 


Maybe I shouldn't feel so guilty for my consulting rates...

Re: SQL Injection Prevention 101

2005-08-18 20:29 • by AC
41208 in reply to 41198
dubwai:
Anonymous:

Allowing only stored procedure access to a database is a
huge WTF and should only be favored by psycho DBAs.  It's
like the cops fighting speeders by making everyone take the bus. 
Then only the bus drivers can speed.



Yeah, I mean, it's just like have a controlled production
environment.  WTF, why shouldn't anybody be able to go and do
whatever they please.  Encapsulation, that's stupid too.


Anonymous:


Just try and implement a sensible caching or object relational mapping strategy when you are in this scenario...



Huh?  Why would that be a problem?  Stored procedures are just as relational as any other type of SQL.


Anonymous:


there are lots of ways to prevent SQL injection attacks. 
Allowing only stored procedures is not one on its own, as this case
proves. 



Again, huh?  The WTF is that the person was executing a
statement outside of a stored procedure.  If the developer only
called a stored procedure, he wouldn't be able to create one.  How
do you create a SQL injection attack if all you do is call stored
procedures?


Anonymous:


Who is to say that the consultant wasn't filtering for SQL injection attacks on the code that invoked the stored procedure?



That the consultant wasn't aware of them is a big clue.  And why reinvent the wheel?


A stored procdure is a great way to create clean interfaces between
code and the DB.  It's a lot easier to refactor code to
call the same stored procedure in a new DB than to refactor
all the SQL in your code.  In Java, for example, it's just a
matter of changing drivers to switch DB vendors if you only use stored
procedures.  It also insulates the code from table structure
changes.





Portability is a good point but I've never been able to change a schema
and NOT change the SPs. Plus the poster is just saying that a lot of
ORM systems have a hard time with SPs. I agree.



Here:



http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#sp_query

Re: SQL Injection Prevention 101

2005-08-18 21:05 • by Matías
41210 in reply to 41206
Anonymous:

The only thing he did was allow a 16k character sql statement instead of 8k.


Actually, not even that. If the database in
question has an 8000 character limit on the varchars, as is quite
likely, then concatenating two big strings that add up to over 8000
characters will truncate. So this is *even dumber* than it first
appears.




Not in T-SQL, no. Even though there is a definite limit to the size of
CHARs/VARCHARs, you can concatenate them and it won't truncate.


For instance (for Sybase, the limit is 255),




DECLARE @p VARCHAR(255), @q VARCHAR(255)
SELECT @p = REPLICATE('A',255), @q = REPLICATE('B',255)
SELECT SUBSTRING(@p+@q, 254, 4)


would return "AABB".

Re: SQL Injection Prevention 101

2005-08-18 23:20 • by coltonsk
Ok, I'll admit to writing a sproc similar to this, but there is a
perfectly good reason for this.  My former employer, who will go
unnamed (but basically Germany's largest bank),  put a procedure
in place where all the procs had to be reviewed and approved by at
least 2 different groups (one of which didn't have a foggiest idea of
what SQL was and the other one merely knew how to put together a basic
SELECT) before being commited to the database.  This had to be
accompanied by a multitude online forms, all of which had expiration
dates.  If one of the groups didn't approve it in time, you had to
resubmit.  So having gone through a couple of these sproc
submissions, I had enough and simply wrote a proc like the one
above.  As I expected, the sproc got approved and never had to
submit another sproc again.



Chances of SQL Injection attack on my apps?  All of them were
internal, the likelyhood is small.  And if it happens, that's just
the cost of putting stupid policies in place.  Would serve them
right.



Re: SQL Injection Prevention 101

2005-08-19 00:02 • by DJR
WTF

Re: SQL Injection Prevention 101

2005-08-19 01:25 • by Drak
41217 in reply to 41176
A Wizard A True Star:

Oh, I know what the WTF is. They should have called it sp_SADynamicTPSBuilder, of course.


But, seriously...


That EXEC(sql string) function might possibly be the worst idea ever thought of in the entire history of MS SQL Server. If you really really need your SQL to be that dynamic (and I would contend there's absolutely no reason you should) then at least build your strings in the ASP or VB code.


 



We do use EXEC in one of our stored procedures. We use it to flip a table so that rows become columns and columns become rows. This is not possible in SQL 2000 in another way as far as I (and I'm not a databaser, actually) and my boss know...


Ofcourse if there is another way, now would be the rihgt time to mention it [;)]


Drak

Re: SQL Injection Prevention 101

2005-08-19 01:57 • by Dynamic SQL is for brain-dead Devs

One nasty side effect of ExecuteSql is that it runs with the Public permission set.


This means all database objects (tables, other sprocs, user-defined functions, jobs, extended stored procedures, etc.) that the dynamic SQL refers to must have the permissions opened up to Public. The same fools that allow direct table access, are typically too lazy, or too uninformed, to do other than grant ALL to Public.


It's fairly trivial to then take over the server by using xp_CmdShell [1], or a number of other methods.


The WTF here is that there isn't a massive amount of these attacks being published, given how many systems are vulnerable to it.


[1] For those of you unfamiliar with this gem, it can be invoked by anybody with perms to invoke it, yet when it runs, it can execute any operating-system command that the account running Sql Server has the privileges to execute. The typical account used for the SQL Server process is the "System" account. (READ: God Account).

Re: SQL Injection Prevention 101

2005-08-19 02:26 • by Raw
41220 in reply to 41218
Probably just a typo. It should be senile consultant, not senior consultant.

Re: SQL Injection Prevention 101

2005-08-19 02:54 • by emjot
I bet the params are passed to application via HTTP GET query params and WWW is public accessed. Didn't?



Seriously, this is one of my favourite WTFs. It hurts my eyes and my mind hard.

Re: SQL Injection Prevention 101

2005-08-19 03:07 • by Welcome To The Machine
41222 in reply to 41190
Eric:

He didn't get the memo about the TPS reports...  [:D]



Can you forward him a copy of the memo about the new TPS report cover sheets? [;)]

Re: SQL Injection Prevention 101

2005-08-19 03:13 • by azaris
41223 in reply to 41194
After seeing all the SQL-related WTFs here, would any sane DBA (I'll
leave proof of existence as an exercise) allow senior conslutants to
write and execute ad-hoc queries from the code?

Re: SQL Injection Prevention 101

2005-08-19 03:31 • by tufty
41224 in reply to 41218
> It's fairly trivial to then take over the server by using
> xp_CmdShell [1], or a number of other methods.
> The WTF here is that there isn't a massive amount of these
> attacks being published, given how many systems are
> vulnerable to it.

Possibly those who are r00ting such machines are not doing so for the 'zombie bot' aspect but rather for industrial espionage purposes. In which case, victims might be somewhat reluctant to come forward - after all, if your sex toy customer database has just been pwned, you're probably not going to be over-eager to let everyone know. Just a thought.

Otherwise, yeah, hacking into a box with SQL Server on it is not terribly difficult by all accounts. To be honest, most of the web app installations I've come across using SQL Server use 'sa' as the account to connect as, for fuck's sake.

Simon

Re: SQL Injection Prevention 101

2005-08-19 04:01 • by cjs
41225 in reply to 41198
dubwai:

A stored procdure is a great way to create
clean interfaces between code and the DB.  It's a lot easier to
refactor code to call the same stored procedure in a new DB
than to refactor all the SQL in your code.  In Java, for example,
it's just a matter of changing drivers to switch DB vendors if you only
use stored procedures.  It also insulates the code from table
structure changes.





It depends, actually. In a lot of my systems, it's much easier to go
through the code and refactor embedded SQL than it is to change stored
procedures. This is mostly because it's easier to write and change Ruby
code than it is to write and change SQL code.

Re: SQL Injection Prevention 101

2005-08-19 04:27 • by DZ-Jay
41226 in reply to 41156
richleick:
Well, duh!  He is obviously still missing a lot:



CREATE PROCEDURE [SADynamicTPSBuilder]
(
@SELECTS VARCHAR(8000),
@JOINS VARCHAR(8000)
@WHERES VARCHAR(8000)
@ORDERS VARCHAR(8000)
) AS
BEGIN

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

EXEC
(@SELECTS + @JOINS + @WHERES + @ORDERS)

RETURN(-1)

END

I mean seriously, what's the point if I can't specify my where and order by clause.



"I sense the sarcasm."

"Good because I'm laying it on pretty thick."




How about this?



CREATE PROCEDURE [SADynamicTPSBuilder]
(
@SELECTS VARCHAR(8000),
@JOINS VARCHAR(8000),
@OTHER_NON_INJECTION_CODE_REALLY VARCHAR(8000),
) AS
BEGIN

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

EXEC
(@SELECTS + @JOINS + @OTHER_NON_INJECTION_CODE_REALLY)

RETURN(-1)

END

    dZ.

Re: SQL Injection Prevention 101

2005-08-19 04:34 • by DZ-Jay
Oh noooo!  The Brillant Paula Bean (tm) got a job as an DBA consultant... Gawd help us all.



    dZ.



Re: SQL Injection Prevention 101

2005-08-19 04:38 • by DZ-Jay
41228 in reply to 41199
Anonymous:
johnl:

...and how it would affect our planned buctracking/knowledge base system if we allowed free text searches.





Oh man. One typo away from butcracking.




Ewww.  Take your filthy programming fetishes outta here!



    dZ.

Re: SQL Injection Prevention 101

2005-08-19 06:13 • by tökk
41230 in reply to 41225
But then you lose the performance benefit stored procedures have (cached query plans etc)

Re: SQL Injection Prevention 101

2005-08-19 06:29 • by Gah.
41231 in reply to 41200
evnafets:

Obviously the WTF is that he included no exception handling in the stored procedure.
This code needs to be added to the end:

EXCEPTION
  WHEN others 
  THEN
    NULL;
[8-)]


Hmm, which RDBMS is that for then?

Re: SQL Injection Prevention 101

2005-08-19 06:31 • by Pedant
41232 in reply to 41213
Anonymous:
Ok, I'll admit to writing a sproc similar to this, but there is a
perfectly good reason for this.  My former employer, who will go
unnamed (but basically Germany's largest bank),  put a procedure
in place where all the procs had to be reviewed and approved by at
least 2 different groups (one of which didn't have a foggiest idea of
what SQL was and the other one merely knew how to put together a basic
SELECT) before being commited to the database.  This had to be
accompanied by a multitude online forms, all of which had expiration
dates.  If one of the groups didn't approve it in time, you had to
resubmit.  So having gone through a couple of these sproc
submissions, I had enough and simply wrote a proc like the one
above.  As I expected, the sproc got approved and never had to
submit another sproc again.





Chances of SQL Injection attack on my apps?  All of them were
internal, the likelyhood is small.  And if it happens, that's just
the cost of putting stupid policies in place.  Would serve them
right.










I worked on a project for a very large uk company performing support of
their main processing systems. Due to one nonce doing an update to a
table, but somehow losing the 'where' clause, we were all subsequently
made to have an 'sql buddy' watching over us whenever we needed to fire
sql against the tables. I don't think it mattered whether they knew sql
or not. The managers told us it was to 'protect us'....







« PrevPage 1 | Page 2Next »

Add Comment