Class RememberMe
Provide Remember Me functionality to restore a user's login state in a new session
This incorporates ideas from Barry Jaspan's article found here: http://jaspan.com/improved_persistent_login_cookie_best_practice
There are problems with most of the published articles on the subject of persitent authorization cookies, most specifically when dealing with concurrency issues in the modern web. If two or more requests from the same browser instance arrive at the server in a short time (i.e. impatient reload, restored tabs) all presenting the same one use token in the auth cookie, one will work, and the others will fail.
Using this functionality is a security risk. Ideally, this should only be used over ssl, but even then, the possibility of cookie theft still exists. Present that stolen cookie and the thief can become the authorized user. The following details the steps taken to provide a smooth user experience while minimizing the exposure surface of this risk.
Each time a new persistent auth cookie is requested, a new "series" is started. Associated with the series is a one time token, that changes whenever it is used. To "debounce" any concurrent requests: Instead of erasing the old token immediately, a short expire time is set. If a cookie is used with the expiring token, it is updated to the new session. After the expire time elapses, the old token is erased. If a cookie with an invalid series is presented, it is erased and ignored. If a cookie has a valid series, but an unknown token, we treat this as evidence of a stolen cookie or hack attempt and clear all stored series/tokens associated with the user.
Additionally, the surrounding application logic is aware that the persistent auth logic was used. We only supply a saved id, the application must process that id. That "fact" can be saved to require authentication confirmation as appropriate.
Package: RememberMe
Category: Xoops\Core\Session
Copyright: 2015 XOOPS Project (http://xoops.org)
License: GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
Author: Richard Griffith richard@geekwright.com
Link: http://xoops.org
Located at oops_lib/Xoops/Core/Session/RememberMe.php
public
|
|
public
integer|false
|
|
public
|
|
public
|
#
invalidateAllForUser( integer $userId )
Invalidate all existing "remember me" cookie by deleting all the series/tokens |
protected
boolean
|
|
protected
|
|
protected
boolean
|
#
hasSeriesToken( string $series, string $token )
Get the values associated with a given series and token |
protected
array|false
|
#
getSeriesToken( string $series, string $token )
Get the values associated with a given series and token |
protected
|
#
setSeriesToken( string $series, string $token, array $values )
Get the values associated with a given series and token |
protected
|
#
unsetSeriesToken( string $series, string $token )
Get the values associated with a given series and token |
protected
|
|
protected
|
|
protected
|
|
protected
|
|
protected
string
|
|
protected
string
|
|
public
|
#
createUserCookie( integer $userId )
Create a new user cookie, usually in response to login with "remember me" selected |
protected
|
|
protected
array|false
|
|
protected
|
#
writeUserCookie( array|string $cookieData, integer $expire = 2592000 )
Update cookie status for current session |
protected
array
|
$userTokens
|
#
array()
|
protected
integer
|
$userId
|
#
0
|
protected
|
$xoops
|
#
null
|
protected
integer
|
$now
|
#
0
|