Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2007, 05:18 PM
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default Security issue

Hi everybody,
I have a big question for you:
in PHP native in order to check an user authentication we were used to perform an action like this:
if($_SESSION["auth"]) echo "authenticated";
else exit();

but using ZF in order to check the privilege, we have to call Zend_Auth::getInstance()
that creates a session cookie, even if the vistor isn't authenticated, haven't we?
After that we have a cookie for session!

Please let me know if I am right and or show me a workaround.

thank you
cheers Fabrizio
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-14-2007, 09:01 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

yes and no.

Zend_Auth::getInstance() actually creates a session name space. I believe the default is 'Default'. Once a user authenticates that namespace recieves an identity. So to check if a user is authenticated you do the following:

Code:
//get an instance of the auth object which is bound to the session namespace 'Default'
$auth = Zend_Auth::getInstance()  
if ($auth->hasIdentity()) {
   echo "Authenticated!";
} else {
   echo "Not Authenticated!";
}
Here's a good tutorial for getting started with Zend_Auth

What I prefer is to actually create my own session namespace in my bootstrap:
Code:
$session = new Zend_Session_Namespace('Default');
Zend_Registry::set('session', $session);
This allows me to use session based features without an authenticated user. Then I setup the auth object to use that session.
Code:
$auth = Zend_Auth::getInstance()  
$auth->setStorage(new Zend_Auth_Storage_Session('Default'));
It seems redundant as I used 'Default' for my namespace, you can call it what ever you want. The reason I prefer this method is to avoid creating multiple sessions. This way I create a session and when the authentication takes place it uses the same existing session vs. creating a new authenticated session. That and I get to play with more Zend gewdness.

Last edited by Elemental : 08-14-2007 at 09:09 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-17-2007, 08:39 AM
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default

I get your point,
but actually my question was realted to the security issues that an instance of auth session could bring to your application.

In my opinion (after have checked the source code of Zend_Auth::getInstance()), in order to check if a session exists ZF creates it executing a call to new Zend_Session_Namespace('Auth')!
So, if it didn't exist before, after checking it will exist, and a cookie auth will be created! It will be empty but in facts it will be created!

Someone maliciuos user that tries to hack our application bypassing the login usin some tecnique of coockie poisoning could find an auth cookie instancieted, even if our purpose was just to check the privileges not to gain them!

Addinctionally I think your idea to set authenticated data in the same session coockie 'Defualt' could be a wrong idea, because of the fact I've just explained.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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 05:05 AM.