TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-06-2008, 05:45 PM   #1 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default Sessions and security/maintenance

So I'm in the middle of cleaning up my session class and trying to optimize it, and as such I decided to go through the manual some more this morning, focusing on sessions and all related methods. I came across session_regenerate_id(), and now I'm curious.

Does it make sense to make use of this, and how costly is it? The first thought that ran through my head was security. If somebody is trying to hijack a session, via whatever method, if I'm regenerating the ID constantly, this should make it a lot harder, no? I added it to my __construct and so far no buggy behavior with my sessions, and no appreciable increase in execution time.

Also, if anybody has any experience with this method, how comes 'delete_old_session' doesn't work? I would assume this should default to true, as it makes it sound like a mess of old session id's are left around if you don't set it, however it defaults to false according to the manual. So, running PHP 5.2.5, I tried using it, and PHP produces a notice, Use of undefined constant DELETE_OLD_SESSION - assumed 'DELETE_OLD_SESSION' in.... I tried it all in lower and uppercase, both produce a notice.
-m
delayedinsanity is offline  
Reply With Quote
Old 05-07-2008, 05:50 AM   #2 (permalink)
The Wanderer
 
Highway of Life's Avatar
 
Join Date: May 2008
Location: Beware of programmers carrying screwdrivers
Posts: 21
Thanks: 0
Highway of Life is on a distinguished road
Default

You should be using
PHP Code:
session_regenerate_id(true); 
That will destroy your old sessions.

And yes, session_regenerate_id() is a good method to use, you shouldn’t notice any decrease in execution or memory consumption when using the function.
Never trust a session id. You should use multiple methods of session authentication to prevent session hijacking.
__________________
- Highway of Life
[ Software Engineer | PHP Developer | phpBB.com Team Member ]
phpBB Academy at StarTrekGuide
Send a message via AIM to Highway of Life Send a message via MSN to Highway of Life
Highway of Life is offline  
Reply With Quote
Old 05-07-2008, 05:59 AM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Thank you.

I do use a few methods, there's an alternate session ID stored in the users table which it authenticates against, and I also attach a hash of the members user agent so if for some reason the user agent string changes halfway through the session it logs them out to help prevent against hijacking. Any suggestions for a fourth line of defense?
delayedinsanity is offline  
Reply With Quote
Old 05-07-2008, 06:09 AM   #4 (permalink)
The Wanderer
 
Highway of Life's Avatar
 
Join Date: May 2008
Location: Beware of programmers carrying screwdrivers
Posts: 21
Thanks: 0
Highway of Life is on a distinguished road
Default

Ah, excellent.
User IP. :) -- you can validate on the xx.xx.xx only match if you wish, for example some users might have a dynamic IP.
or xx.xx if your security does not have to be that tight, but some IP validation should be used.
__________________
- Highway of Life
[ Software Engineer | PHP Developer | phpBB.com Team Member ]
phpBB Academy at StarTrekGuide
Send a message via AIM to Highway of Life Send a message via MSN to Highway of Life
Highway of Life is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:29 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design