News for hackers. Stuff that matters.
Re:No-SQL injection in Mongo PHP by tptacek on Tuesday March 08, 2011 @11:43PM (#2303829)
Yeah these are great comments and all but I'm just saying that, last time I checked, you can't bind a table name as a parameter in the MySQL protocol; if your table names change at runtime based on input, you're back to concatenated queries.
Re:No-SQL injection in Mongo PHP by btilly on Wednesday March 09, 2011 @12:15AM (#2303929)
Oops, I had misunderstood. You're right. It makes no sense to bind table names as parameters, because if you do then the database really has no information from which it can generate possible query plans from.

The way that I solved that particular problem in the past is that I used a templating system to generate my SQL. User input was allowed in ifs in my templates, and as parameters for my queries, and that was it. At no point did I trust user data inside of my SQL.

Re:No-SQL injection in Mongo PHP by rbanffy on Wednesday March 09, 2011 @07:46AM (#2304679)
> you're back to concatenated queries.

Wouldn't it be safer to use a switch statement?

Re:No-SQL injection in Mongo PHP by bmm6o on Wednesday March 09, 2011 @12:31PM (#2305593)
In theory, it should be possible to enumerate your SQL queries ahead of time rather than ever generating one on the fly. In practice, that could be a huge pain of the O(2^n) variety, depending on the application type.
Re:No-SQL injection in Mongo PHP by rbanffy on Wednesday March 09, 2011 @01:23PM (#2305802)
I assume the choice of table names or query templates in the case mentioned (make a report for atypical client C run faster) would be limited to a handful of possible query templates.