This is a question about creating CSRF tokens.
Normally, I would like to create a token based on the unique piece of data associated with a user session and hash and salt with a secret key.
My question is to generate tokens when there is no unique user data to use. No sessions, cookies are not an option, IP address and such things are unreliable.
Is there a reason why I cannot include the string in the hash as part of the request? An example of pseudocode for creating a marker and inserting it:
var $stringToHash = random() var $csrfToken = hash($stringToHash + $mySecretKey) <a href="http://foo.com?csrfToken={$csrfToken}&key={$stringToHash}">click me</a>
CSRF Token Server Side Validation Example
var $stringToHash = request.get('key') var $isValidToken = hash($stringToHash + $mySecrtKey) == request.get('csrfToken')
The string used in the hash will be different for each request. As long as it is included in each request, CSRF token validation can continue. Since it is new for each request and is only embedded in the page, external access to the token will not be available. Token security then drops to $ mySecretKey, which is known only to me.
Is this a naive approach? I don’t have any reason why this cannot work?
thank
csrf
Jim Beam Nov 26 '09 at 21:53 2009-11-26 21:53
source share