tags:

views:

33

answers:

2

When I am grabbing data from my table that require permissions, should all the permission be done there? Such as checking for an admin or if they can view the data (in MySQL)?

Or should I grab it if they have a record at all, then check the specific actions (such as view, add, edit, delete) on the PHP side?

+1  A: 

Do it in PHP. Say you have the user Admin, and you are going to look at the table books. If you do it in MySQL, you have to make a join to see if they can access the data and then grab the data. if you do it in PHP, you check if they have the permission, and if they don't stop processing and never attempt to grab data from books. It is more secure that way if someone tries to exploit your server.

Aaron Harun
one can stop processing in mysql too, or on can limit it so no query will ever give back unauthorized data with SQL (it's even possible to make is such that even if the scripts are compromised the data isn't), however figuring the SQL subroutines to do such for a given security model is very complicated and in most cases it's certainly overkill.
ewanm89
I don't understand how there is a security risk in doing it in MySQL? If I have a LEFT JOIN and it NEEDS to have those permissions, it will return nothing. I am using MySQLi and prepared statements for any user input, not concerned over SQL Injection
Kerry
Disagreed w/Aaron; doing it in MySQL will probably be faster and is no less secure. If your queries only return data that the user has access to, then no problem security wise.
El Yobo
+1  A: 

It's usually more efficient to do everything in SQL but it's also more complicated, and can be a lot harder to maintain.

Mostly it depends on your exact security model and security concerns.

ewanm89
Security needs to be pretty high
Kerry