Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Session handling security

by Fingo (Monk)
on Aug 20, 2002 at 20:27 UTC ( #191588=perlquestion: print w/replies, xml ) Need Help??

Fingo has asked for the wisdom of the Perl Monks concerning the following question:

When using session handling is it okay security wise to just remember the user-name or should I check the password every time (ie can session id's be faked)?

Replies are listed 'Best First'.
Re: Session handling security
by waswas-fng (Curate) on Aug 20, 2002 at 20:35 UTC
    A lot of people will use sessions with some type of MD5 hash of the user information and password as well (in cookies or urls) this way it makes it way harder to fake sessions, and yes sessions can be faked depending on how they are implemented. Many session handlers forget that a substantial portion of the internet (AOL many other ISPS) connect though transparent proxies which makes the originating IP almost worthless in the session state.

      Is this dangerous enough to warrent the speed hit of checking name and pass every time on a site where security is not key (ie I don't use https)?
        Are you providing the sessions or are you using a 3rd party product or are you using perl modules to do it? It really depends why the site is password protected to begin with. If you have no need for security but just have logins to change the look and feel of a site then I would say no. If you have parts of the site that contain personal information or information that is _private_ then I would say it might make sense to deal with the overhead of doing so. The devil is in the details -- what makes sense for one site may not make any for the next.

Re: Session handling security
by ducky (Scribe) on Aug 20, 2002 at 21:36 UTC

    What I've done in the past is to generate a fairly unique base64 string (20 digits or so) and send the user a cookie with that string when they first log in.

    I figure the chance that another user guessing that is low and if they were snooping the line, well, they'd have the password anyway, so why bother with a more elaborate setup?

    I then check the cookie every request and expire the cookie after a time-out of say 1/2hr or whatever (usually user alterable).

    I do this over the built-in password checking because, well, I wanted to figure out how and prefer the little login boxes over the pop-up style =)

    Of course, these were all in the name of seeing if I could do it, so I didn't consult the all-mightly CPAN before re-engineering the wheel.


Re: Session handling security
by Ryszard (Priest) on Aug 21, 2002 at 07:25 UTC
    Session ID's can be faked, there is no doubt about it. All one has to do is change the value in the cookie (if using cookies) or the parameter value. It really is a no brainer to fake.

    Now the good news. What is not so easy to do is to determine how the session id is created. Depending on the level of security you want, you may have the session id changed every time a user views a page, or change it for every session.

    To do my session stuff, i use MD5 and a combination of various things including an arbitrary string, with the session id lasting as long as a session (a user is logged in). I dont really need the security to change the session id each time a page is viewed.

    Each time a logs in you give them a session key, either in a cookie, or html parameter somewhere, then and save it server side in a database against the user_[id|name].

    You have the overhead of making a call to the database each time, however there are many things that can be done to tune this access, depending on the level of performance you require, ie caching the db in memory, using placeholders in you DBI (if you're using DBI), using mod_perl to create persistant connections (again, if you're using DBI) etc etc.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://191588]
Approved by snafu
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2020-10-27 18:24 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (257 votes). Check out past polls.