2020-04-29, 09:35 PM
Dear mybb community
I have an authorization php script which only relies on Cookies and DataBase queries.
It doesnt include any MyBB scripts, and it is not terminating only if you have a valid SessionID and a specific UserID
I wrote it because i didnt wanted it to take up much memory in the first place.
>> First i check if mybbuser is existing in the Cookie
>> Then i grab the UID from the Cookie
>> Here its a simple UID comparsion with the whitelist
>> Here i am preparing to fetch the SID's from "mybb_sessions" for this UID
>> And then i am fetching those SID's , until ONE of them is equal to the SID from the Cookie
Script terminates if no matches found.
My question is if this code is secure enough to ensure, that only a logged member with a specific UserID is able to pass through this.
Or is there something that i am horribly missing ?
Thank you
I have an authorization php script which only relies on Cookies and DataBase queries.
It doesnt include any MyBB scripts, and it is not terminating only if you have a valid SessionID and a specific UserID
I wrote it because i didnt wanted it to take up much memory in the first place.
>> First i check if mybbuser is existing in the Cookie
if(array_key_exists("mybbuser", $_COOKIE))
>> Then i grab the UID from the Cookie
$USER_ID = substr($_COOKIE['mybbuser'], 0 , strpos($_COOKIE['mybbuser'], "_"));
>> Here its a simple UID comparsion with the whitelist
if(!in_array($USER_ID , $uid_list)) exit;
>> Here i am preparing to fetch the SID's from "mybb_sessions" for this UID
$query = $pdo_forum -> prepare("SELECT sid FROM mybb_sessions WHERE uid = :uid");
$query -> execute(array("uid" => $USER_ID));
>> And then i am fetching those SID's , until ONE of them is equal to the SID from the Cookie
Script terminates if no matches found.
while($sid = $query -> fetchColumn())
{
if($sid == $_COOKIE["sid"]){ $SID_OK = true; break;}
}
if(!$SID_OK) exit ;
My question is if this code is secure enough to ensure, that only a logged member with a specific UserID is able to pass through this.
Or is there something that i am horribly missing ?
Thank you