CGI:Session and security

Hello Folks,

There are some simple standard problems which crowd my brain :slight_smile:

  • creating a session using a hidden field like cgi[‘sess_id’] instead
    of a cookie … or first try the cookie and if it’s rejected, go
    the other way

This should be easy to achieve. Either put automatically a hidden field
after each with the content that would be otherwise written into
the cookie. This is somewhat kludge, but in PHP it works very well. At
least ERuby should be able to do that.
Or override “cgi.form { … }” to “old_form { hidden { … } }”

The better way would be to give the programmer a chance to manage
the sess_id for himself … having an option not to store the sess_id
into a cookie and having an attribut like Session.sess_id

… but as far as I see, none of these ways are implemented. Why not?

  • since session files are mostly readable by other scripts/users,
    passwords shouldn’t be stored directly. So it should be stored
    encrypted. This is especially useful if the CGI script doesn’t
    contain any passwords (the ideal case ;-)) and uses the password
    the user entered to authorize against LDAP, a database, or whatever.

The best way would be to created a random key and encrypt the entered
password with it. The one is stored in the session (at the server),
the other is stored in a cookie or a hidden field (at the client).
So the attacker must catch the session file and have access to the
browser of the user. And both, the session file and the cookie, are
removed after the session, so the attacker must catch these two
during the session. As long as HTTPS is used, and noone can be
at two places at the same time, this would be secure.

An even better way would be to automatically encrypt the whole
session, so that the sess_id consists of two parts: The id of
the session file (to find it), and the (initially) random key
used to encrypt/decrypt the session file. At least this could
be possible in a transparent way. A kind of
CGI::Session::EncryptedFileStore should be possible, isn’t it?

Probably CGI::Session::MemoryStore is already the solution of this
problem, but it’s only shortly mentioned in the Ruby Book. So
I don’t know …

Of course, using SuExec the session file would have another owner
etc., so then it would be secure, too. But secure sessions should
be possible without an extra user for each CGI script :slight_smile:

So my thoughts about these issues. Does anyone know in what way
they are implemented or why they better shouldn’t?

Thanks,

···


Volker Grabsch
—<<(())>>—
\frac{\left|\vartheta_0\times{\ell,\kappa\in\Re}\right|}{\sqrt
[G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint!c_\hbar\right]}}}

Volker Grabsch wrote:

There are some simple standard problems which crowd my brain :slight_smile:

… MMh, and no answer yet.

Isn’t there anyone dealing with this kind of issues?

So my thoughts about these issues. Does anyone know in what way
they are implemented or why they better shouldn’t?

Well, I should ask this in another way :slight_smile:

Did anyone actually implement this kind of session security?

… or …

Did anyone consider that, but didn’t do so for good reasons?

Greets,

···


Volker Grabsch
—<<(())>>—
\frac{\left|\vartheta_0\times{\ell,\kappa\in\Re}\right|}{\sqrt
[G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint!c_\hbar\right]}}}

Volker Grabsch wrote:

There are some simple standard problems which crowd my brain :slight_smile:

… MMh, and no answer yet.

Isn’t there anyone dealing with this kind of issues?

Have you ever tried it? Makeing a hidden form field form a session is not
so complicated:

puts “<input type="hidden" name="id" value="#{@session.session_id}">”

and earlier init the session with something like:

puts cgi.header(“text/html”)
@session = CGI::Session.new({“session_key” => “id”})

works like a charm. To disable the cookie I put the cgi.header call befor
the CGI::Session.new call. I’m not sure if there is a better sollution to
this (I started working with ruby just a few days ago.)

So my thoughts about these issues. Does anyone know in what way
they are implemented or why they better shouldn’t?

Well, I should ask this in another way :slight_smile:

Did anyone actually implement this kind of session security?

… or …

Did anyone consider that, but didn’t do so for good reasons?

Remember sessions can be hijacked so it is uesful to store some additional
info in the session file (like the IP address of the client and a session
timeout). This does not matter if it is a cookie or a get/post field.
IMHO storing sensitive data in a cookie is a bad idea.

···

On Tue, Sep 02, 2003 at 04:32:30PM +0900, Volker Grabsch wrote:


:wq Claudio

Just for the record, %Q makes that kind of stuff more readable and less error
prone:

puts %Q()

– fxn

···

On Tuesday 02 September 2003 11:33, Claudio Jeker wrote:

puts “<input type="hidden" name="id" value="#{@session.session_id}">”