Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2010, 10:22 PM   PM User | #1
four0four
Regular Coder

 
Join Date: Jun 2008
Posts: 104
Thanks: 71
Thanked 0 Times in 0 Posts
four0four is an unknown quantity at this point
Arrow How can I improve the security of this?

I'm not sure if there's really a way to make this more secure - but, this is what I have...

I have a form with a hidden field that retrieves a hashed user ID from a session, and then inserts that info into the hidden form field.

How can I make sure that a user doesn't change this info when submitting the form?

I'm guessing that it's impossible to guard against, since it's a hidden form field and a user could simply change either the session info or just the hidden form field data.

Any ideas on how to make this more secure?

Thanks!
four0four is offline   Reply With Quote
Old 01-11-2010, 10:50 PM   PM User | #2
ninnypants
Regular Coder

 
ninnypants's Avatar
 
Join Date: Apr 2008
Location: Utah
Posts: 504
Thanks: 10
Thanked 47 Times in 47 Posts
ninnypants is an unknown quantity at this point
What exactly are you trying to do with the form field?
ninnypants is offline   Reply With Quote
Old 01-11-2010, 11:40 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Why pass the value along if you're already tracking it in a session?
The answer is you can't, any values passed through a form are given to us from a client, so you need to validate everything yourself.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-12-2010, 07:35 AM   PM User | #4
four0four
Regular Coder

 
Join Date: Jun 2008
Posts: 104
Thanks: 71
Thanked 0 Times in 0 Posts
four0four is an unknown quantity at this point
I have a registration page that takes the user to a payment page after successfully signing up.

When the user first registers, a random hashed user ID is generated for that user and then inserted into my database and into a session.

On the payment page, the user ID from the session is inserted into a hidden form field. This user ID is submitted to PayPal when the user makes their first payment. PayPal needs a custom user ID to update my records using the PayPal IPN.
four0four is offline   Reply With Quote
Old 01-12-2010, 12:57 PM   PM User | #5
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
In that case, I'd leave it as it is. If any user tries to tamper with the data it won't let them use the service even if they have paid, so it will be them that is losing out not you
__________________
My site: JayGilford.com
Resources:
PHP Pagination Class | Getting all page links | Handling PHP Errors properly
If you like a users help, show your appreciation with the rep and thanks buttons :)
JAY6390 is offline   Reply With Quote
Old 01-12-2010, 01:31 PM   PM User | #6
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,513
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Nice reply Jay.

haha

In fact, if the op has their email, he can send them an email
asking them to play with the data again, maybe a few times ;-)
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-12-2010, 01:36 PM   PM User | #7
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
yeah
__________________
My site: JayGilford.com
Resources:
PHP Pagination Class | Getting all page links | Handling PHP Errors properly
If you like a users help, show your appreciation with the rep and thanks buttons :)
JAY6390 is offline   Reply With Quote
Old 01-12-2010, 11:45 PM   PM User | #8
four0four
Regular Coder

 
Join Date: Jun 2008
Posts: 104
Thanks: 71
Thanked 0 Times in 0 Posts
four0four is an unknown quantity at this point
Thanks for the help!

I hash the e-mail address from the registration page with a random salt, using SHA-1. Then I use that hash as the user ID for each user in the database.

So, I'm guessing it would be fairly hard for a malicious user to generate a hash (user ID) for an existing user anyways, right?

I was even thinking of using SHA-512, but that's probably taking it too far.
four0four is offline   Reply With Quote
Old 01-13-2010, 12:07 AM   PM User | #9
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
I see no reason why you shouldn't use SHA512
__________________
My site: JayGilford.com
Resources:
PHP Pagination Class | Getting all page links | Handling PHP Errors properly
If you like a users help, show your appreciation with the rep and thanks buttons :)
JAY6390 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:25 AM.


Advertisement
Log in to turn off these ads.