-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fixed the multi tab issue through unset used token only and set cookie default path /
to generate new token while ajax calls
#117
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,10 +302,11 @@ private static function isValidToken($token) { | |
|
||
// Clear all older tokens assuming they have been consumed | ||
foreach ($_SESSION[self::$config['CSRFP_TOKEN']] as $_key => $_value) { | ||
if ($_value == $token) break; | ||
array_shift($_SESSION[self::$config['CSRFP_TOKEN']]); | ||
if ($_value == $token) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If two requests are sent at same time with same token, one of the request might fail because of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per logic implemented, token generate based on requests so every request has a unique token and it should not be the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A token is generated when the former token is consumed. Imagine two tabs load path /a at T0. Both with get token1. Now if Tab1 sends request and it's verified. A new token will be sent. The cookie would be updated and now both Tab1 & Tab2 has same token again. However, imagine request originating from both tabs at the same time, with same token: token1 and compare the results with current and proposed logic. |
||
unset($_SESSION[self::$config['CSRFP_TOKEN']][$_key]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, with this if multiple tabs get new tokens and only few of them use the token it may pile up data in session variable with no TTL approach to clean it. Unless ofcourse the whole session is destroyed. |
||
return true; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's expectation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have set a path here to generate a new token on every ajax request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean how does
'/'
helps?