Is it correct to use form field(hidden) for storing Session Token instead of using Cookies? What is the security risk associated with it?
|
|
To be protected against CSRF while also hardening against XSS, store your session IDs in cookies (with httpOnly flag) and use separate session-bound form tokens that you validate upon POST. By combining these methods, you prevent an attacker that has found XSS from stealing session IDs, while you still protect against CSRF in a meaningful way. Using the session ID as form token enables an attacker to steal the session ID through XSS. |
|||
|
IMHO, by far the biggest disadvantage is that you need to explicitly add code to repopulate the session identifier into each and every page, potentially in multiple places. Using a form field is only going to work where you've got a form and that's the only way to navigate off the page. So you also need to add code to parse every href on the page and add the session id (since you don't want to send your session id to other sites). What about ajax requests? Javascript driven navigation? You should also be change the session id at authentication - so you've also broken the behaviour of the back button. Yes, you can solve all these problems by throwing code and effort - but more code = more bugs = less security. Another consideration is that some applications use multiple session identifiers - managing this outside of cookies would be an even bigger PITA. |
|||||||
|
|
No, you should not use GET or POST parameters for session identifiers. Session ID should only be transmitted via HttpOnly cookies. There are at least three reasons for doing so:
To stop CSRF, it is important to also include a CSRF token in a hidden form field or in the URL of every POST request. However, the CSRF token does not need to contain the session ID, and it is safer if it does not contain or reveal the session ID. A safer choice is to use a random nonce or a one-way hash of the session ID as the CSRF token. |
|||||||||||||||
|
|
Three common approach for transfer of Session Identifier between Browser and Server
All have their advantages and disadvantages, but since you asked about Hiddel Fields only here are few advantages and disadvantages
Thats what I can think of right away, may be others can point more advantages and disadvantages And yes I am assuming you have your Server Side Session Tracking and management code and logout logic written correctly |
|||||||||||||||
|