Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do my web app's users need direct access to my database?

I'm creating a web app that users will create an account for, which allows them to read/write data on a database. I'm about to start creating the login authentication part of the website, and its my first time really doing this part. As I understand it, I'm going to create a users table which will store all the necessary login info for the website.

I know there are also database roles/permissions. My question is about how the 2 relate in this instance. Do I need to authenticate the users on the website and the database? My thought process was that if all of my PHP scripts are set up in such a way that the session data will only allow authenticated users read/write to the DB, then I don't need to do anything on the database end, but I want to make sure I'm thinking about this correctly.

Is that clear as mud?

like image 384
hyphen Avatar asked Mar 22 '23 08:03

hyphen


1 Answers

If I understand correctly, your question is wether or not your users need access to your database.

Your users are not going to communicate with the database directly. Your app will. Your users are only going to use your app which will act as an interface between the user and the database.

Therefore, only the app needs access (and the appropriate permissions) to the database. Because it now has access to the database, it becomes responsible for making sure that only the right people can perform certain actions. (by means of a login- and permission system)

If not all users should have the same permissions within your app (you might have normal users and administrators), you need to create a permission system within your app that checks wether a user has the appropriate permissions to perform a certain action.

For instance if someone tries to delete some important data, you

  1. make sure he's logged in (if he's not, redirect to the login page)
  2. make sure he has the appropriate role / permissions (in this case he should be an administrator - if he's not, cancel the action)

Symfony's page on Security gives some insight. Just skip the Symfony-specific parts and read about the general idea.

like image 129
Nic Wortel Avatar answered Mar 31 '23 16:03

Nic Wortel