csrfVerifyToken does not invalidate the token

February 06, 2019
coldfusion

When you are using csrfGenerateToken and csrfVerifyToken with unique categories, the token that is generated remains valid until another token is generated with the forceNew argument set to true.

Here is a code snippet which illustrates this:

<cfoutput>
    <cfset tokenVar = createUUID()>
    <cfset csrf1 = csrfGenerateToken(tokenVar, true)>
    csrf1: #csrf1#
    verify csrf1: #csrfVerifyToken(csrf1, tokenVar)#
    veryif again: #csrfVerifyToken(csrf1, tokenVar)#
    <!--- generate a new token --->
    <cfset csrf2 = csrfGenerateToken(tokenVar, true)>
    csrf2: #csrf2#
    <!--- this should verify --->
    verify csrf2: #csrfVerifyToken(csrf2, tokenVar)#
    <!--- this should no longer verify --->
    verify csrf1: #csrfVerifyToken(csrf1, tokenVar)#
</cfoutput>

The results of this code is something like this:

csrf1: 14EEDB763BA6E9B68A16A25ED34501778EED8681
verify csrf1: YES
veryif again: YES 

csrf2: 2B1CC298E1E64EAEFB7E3D2FCA7608A9280950DF
verify csrf2: YES
verify csrf1: NO 

As you can see csrf1 remains a valid token until we call csrfGenerateToken again, at that point csrf2 is the valid token for the user's session.



Related Entries

This entry was:

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?