views:

41

answers:

2

Hi,

I am having a problem in understanding the security issues with the following scenario. I have a site that has user registration and they can create events by logging in. If I am logged in as a user and i am in a url like http://abc.com/index.php?page=edit&pageid=45. I am seeing this page after logging in other wise it will show the log in screen..but after logged in and if I change the url from http://abc.com/index.php?page=edit&pageid=45 to http://abc.com/index.php?page=edit&pageid=567

I am able to edit that page..which is a security issue. how to handle this? is there a best way to handle any editing in the url? Please guide me. Or how can I handle this via scripting..by checking anything like username and it's association with the page id's?

please guide me.

I was thinking something like not showing the pageid variable in the url and somehow pass it as hidden from page 1 to page 2..but i don't know how to exactly do this or if it's a good solution at all.

regards

+1  A: 

one possibility is setting and using the $_SESSION variable to determine if a user is allowed to visit a certain page. Another possibility is to use post instead of get for your login form. let me know if i can elaborate.

edit:

<form method="get" action="login.php" name="form"></form>

vs

<form method="post" action="login.php" name="form"></form>

after login, you can set

 <?php $_SESSION['user_id'] ?>

and at the top of the page you are using, you can have a statement like

 <?php if($_SESSION['user_id'] != $_POST['pageid']{//not valid} ?>
Orbit
hi thanks brandon for the quick reply. can you please gudie me the post option from the log in form? this is what an user can do . 1) go to the site. 2)click on my account and log in. 3) show him the list of events he/she had created. 4) each event will have an option for a)editing. 2) deleting c)mail it!. so whatever they click, i have the event id and/or the date in the url. so user a is logged in and if he just changes the id in the url, he can edit user b's events..and do the same with the mail/delete options. please help me.
gan
Using POST instead of GET won't help much. Any self-respecting hacker can fire off a POST request.
kijin
so what is the option? will url rewrite helps?
gan
yes, was about to say this isn't really the way to go. you are going to also need to implement some sort of session tokens for authentication. i'll add something above
Orbit
thanks again brandon..but in my case, i show these "edit/delete/mail" options inside the user account..so when they click on it and they can edit the id in the url..so no form action here? ma i missing somehting. ex - after an user logged in, he/she will see 1) title - date - description --- edit |delete | mail..and the list goes like this.
gan
it's still a form action, just change the method="get" to method="post"
Orbit
the parameters will not be passed via url
Orbit
The id should not passed by url as a first option. You can try to use ajax if you need to use GET method instead of POST. Maybe you can try md5 function in order to change the id and it could be more difficult to remember the id for other users... but the risk will be always present!!
Nervo Verdezoto
thank you all. i couldn't avoid the id passed via url, i tried to verify the user id and then show the page or redirect. thanks for all the quick help and ideas that I can keep in mind.
gan
+1  A: 

I think its fine passing the pageid in the url. So the next thing is, making sure the user can only edit their page. What I would do is save the users id in the table with the events.

Then on the edit page when you get the events information you can check the user id (from the table) with the user id from the person logged in.

Something like this

// I don't know how your query works, but it would go here.

// Then before you output the edit form, Add something like this
if( $_SESSION['user_id'] == $event_result['user_id'] ) {
    // They match, show the form
}else {
    // they don't match
    echo 'Excuse me, what are you doing?';
}
Baylor Rae'
thank you. i tried what you said and it looks like it's working fine. thanks again.
gan