silverstripe/sapphire — pull request #1000 by chillu (2012-12-06 16:43:31+00:00)
Title: API Storing alternative DB name in cookie rather than session

Session is not initialized by the time we need to use
the setting in DB::connect(). Cookie values get initialized
automatically for each request.

Tightened name format validation to ensure it can only
be used for temporary databases, rather than switching
the browser session to a different production database.

Doesn't implement any kind of "signed cookie" mechanism,
because I can't think of a way to retain whatever secure token
we would base this cookie on. If we set an encrypted (not hashed)
cookie, the decryption passphrase needs to be stored on the server.
We could of course set a global one on the filesystem,
but that sounds like a bit of overkill to me.

On the long run, I would like to extract this whole "alternative DB" stuff
into module which hooks into the `DB` class. Its fairly security sensitive code,
there's no good reason it should even exist on production sites.
This would also make securing cookies less relevant.