0

I have a website that check for CSRF tokens when a user logs in. The form looks like

<cfoutput>
    <input type="hidden" name="token" value="#CSRFGenerateToken()#" />
</cfoutput>

Later it is checked with

if (framework.getCGIRequestMethod() == "post" && !CSRFverifyToken(rc.token))    {
    rc.arMessage.append("<b>Debug:</b> Fail Token");

    return;
    }

I would like to verify that this is actually checking. Does the token ever expire or timeout? Changing this.name= in application.cfc does not seem to do anything. is the token based on domain name?

I need to test this. I don't need to automate the testing, but just test it somehow.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • According to the docs, the values should be created and put into the current session. Maybe dump that and verify the value exists there? You should be able to have one for the entire session or force a new value to be used with each form (which seems like overkill). https://cfdocs.org/csrfgeneratetoken – Adrian J. Moreno Oct 21 '19 at 00:29
  • It is interesting that in the linked documentation, all the examples are a part of forms. Not one is in a session scoped variable – James A Mohler Oct 21 '19 at 02:04
  • I think that function essentially does, "if this session variable doesn't exist, create it and define it to be this value". Then submits that value as a form field variable, which lets you verify the form scoped variable value against the session variable value. – Adrian J. Moreno Oct 21 '19 at 04:55

1 Answers1

1

For testing this, use something like https://www.getpostman.com/.

Target the form's action page:

  • Create a GET request; verify it throws an error.
  • Create a POST request without the token field; verify it throws an error.
  • Create a POST request with the token field and with a value that does not match the value generated by CSRFGenerateToken(); verify it throws an error.
  • Create a POST request with the token and the correct value; verify it processes correctly.
Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44