Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token generation mismatch: hidden input does not match the session variable #12

Open
jamespsterling opened this issue Jan 14, 2016 · 4 comments
Assignees
Labels

Comments

@jamespsterling
Copy link

Inputs on form,

<!--
--><input type="hidden" name="_CSRF_INDEX" value="v6Dzi3KrRDV68kNdPFCES+UU"><!--
--><input type="hidden" name="_CSRF_TOKEN" value="wLoNJygvlKTxBEuhTa/WCjnvtoYldgmTet7MsFQlXU0=">

Session variables dumped at the end of page,

array(1) {
  ["CSRF"]=&gt;
  array(1) {
    ["v6Dzi3KrRDV68kNdPFCES+UU"]=&gt;
    array(4) {
      ["created"]=&gt;
      int(20160114152843)
      ["uri"]=&gt;
      string(1) "/"
      ["token"]=&gt;
      string(44) "T0kXM8I9nzUFv3w7flJTlbOjFa1OEMNR+5xwnHvpqr4="
      ["lockto"]=&gt;
      string(5) "login"
    }
  }
}
@paragonie-scott
Copy link
Member

What is the value of protected $hmac_ip?

@ncou
Copy link

ncou commented Feb 3, 2016

Hi,

Same thing here. the token set in session is different from the value in the hidden text field.
The _CSRF_INDEX is the same in session and in the hidden text field.

The validateRequest return "TRUE" even if the value in the field is different from the value session.

$hmac_ip is TRUE

@ncou
Copy link

ncou commented Feb 3, 2016

After a quick debug, it's because hmac_ip is TRUE.

If set to false, the token value in the hidden field is the same than in the session.

@paragonie-scott
Copy link
Member

Yep. What this feature does is, instead of just placing the CSRF token in the form output, it outputs hash_hmac('sha256', $IPaddress, $csrfToken).

anti-csrf/src/AntiCSRF.php

Lines 162 to 174 in 606274f

if ($this->hmac_ip !== false) {
// Use HMAC to only allow this particular IP to send this request
$token = $this->encode(
\hash_hmac(
$this->hashAlgo,
isset($this->server['REMOTE_ADDR'])
? $this->server['REMOTE_ADDR']
: '127.0.0.1',
\base64_decode($token),
true
)
);
}

I'm tagging this as a documentation bug.

@paragonie-scott paragonie-scott self-assigned this Feb 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants