News for hackers. Stuff that matters.
Re:A guide to preventing SQL injection by axod on Tuesday September 15, 2009 @01:15PM (#824243)
Do people really use variables based on raw userdata to select table/columns? Seems like an incredibly rare case, and bad design. I've never seen/used it.

Parameterized queries are a magic totem against injection, unless you mix them with concatenation of unclean userdata. Which would be silly.

Re:A guide to preventing SQL injection by tptacek on Tuesday September 15, 2009 @01:17PM (#824249)
Of course they do. Sort columns send "ASC" and "DESC", pagination limits and offsets are sent in offset= parameters, etc. How else do you think people do it, other than the most obvious way?

Don't make the problem even worse than it is by trying to downplay it just because you know what you're doing.

Re:A guide to preventing SQL injection by axod on Tuesday September 15, 2009 @01:52PM (#824321)
OK you got me on those 2 cases. For sort order:

$sort_order=="ASC"?"ASC":"DESC"

For offsets and limits convert/parse it to a number first and ensure it's within sane bounds.

You're right though. Parameterization isn't a magic bullet that allows you to forget about all other unclean data if you're using other unclean data in an SQL query.

Surely we all know this though? :/

Re:A guide to preventing SQL injection by tptacek on Tuesday September 15, 2009 @02:04PM (#824355)
My advice is, pass page= as your pagination and pass 1/0 in for ASC or DESC. If you have selectable columns, number them in the parameters, don't name them.

Point being, when you compose the query, you should never be inserting text from parameters; you should be converting parameters into known-good values.