I'm a little confused about Charles Miller's article, "Persistent Login Cookie Best Practice" because I can't understand how the code prevents someone stealing the cookie and login in a different computer.
I have seen and read the following topics:
- https://stackoverflow.com/a/244907/3355243
- https://stackoverflow.com/a/30135526/3355243
- https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#title.2
In all of them it explains how to implement a more secure login system, although I can't figure out how it prevents from stealing a cookie, copy paste into the console and login with it, even if dealing with two different fields (series/selector and token).
document.cookie="theCookieNameFromWebsite=theCookieValueFromVictim";
The paragonie.com link says:
CREATE TABLE `auth_tokens` (
`id` integer(11) not null UNSIGNED AUTO_INCREMENT,
`selector` char(12),
`token` char(64),
`userid` integer(11) not null UNSIGNED,
`expires` datetime,
PRIMARY KEY (`id`)
);
The automatic login algorithm looks something like:
- Separate selector from token.
- Grab the row in auth_tokens for the given selector
- Hash the token provided by the user's cookie with SHA-256
- Compare the SHA-256 hash we generated with the hash stored in the database, using hash_equals()
- If step 4 passes, associate the current session with the appropriate user ID
How d'hell this prevent me from stealing the cookie and use it to log me in the account of my victim?