简体   繁体   中英

Protecting access token from XSS attack

I've been doing some research on where to store access token after login. People say local storage is not secure since it can be read using javascript (vulnerable to XSS) and recommend http-only cookies instead.

But let's say my website is vulnerable to XSS and some malicious code gets run to fetch data from my API. It should still work since the cookie just gets automatically added to the request right? They don't know what the cookie is but the request still works in the end. With XSS the malicious code would be running as if it is from my site.

Am I correct in this?

You are correct, the attacker will able to make what ever your api allows.

The Idea behind "saving the token in an HTTP only cookie" is to prevent from client side to access the token in order to steal it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM