I developing something using PHP/MySQL. Architecture is such that each user will have own (different) DB name, inside that database, tables are called same for everyone. So basically if "bad" user can switch his DB name to someones else - he get access to someone's data means that security is breached.
- What is best way to keep such user specific data such in my case his database name?
- But I guess that answer will be
$_SESSION
superglobal ? If so how safe is it? Can user (httponly) change value of variable stored in$_SESSION
? Particularly if I keep plain db_name in there? Or if I paranoid about it should I hash that db_name -> keep it in session -> read it -> unhash on server side -> give user his database? If so any good advice what encrypting/decrypting I could use? (I have no idea tbh)
Many questions, but they all pretty narrow - thank you in advance!
Edit: I'm afraid i didn't explain myself right:
By different database (or database name) i mean same MySQL instance, just different databases inside (like CREATE DATABASE "sec_login"; USE "sec_login";
in terms of SQL language) so for example I'll have following databases:
- sec_login (with tables: members,loging_attempts, etc..)
... - db_user1
- db_user2
... - db_user1001
So whenever e.g. user2 logins it gets his $db_name = db_user2;
when user1001 comes $db_name = db_user1001;
and then program will serve them with same logic regarding tables inside those databases.
So yes my question was where to keep in this case value of $db_name = db_user2;
Thank you @ Nathan Hazout I got your answer about where does $_SESSION
being kept. And thanks for a good link! Useful and bookmarked for reading it second time :)
About safety: I totally agree on "...as safe as you make it." but just wanted to know what are the odds that "bad" user can get access to someone else's $_SESSION
. Correct me please if I'm wrong - to steal others variables in $_SESSION
is same as to steal others session_id, right?