Every method of storing token on the client-side has some weakness:
- storing the token in HTTPOnly cookie makes the application vulnerable to CSRF attack
- storing the token in localStorage makes the application vulnerable to XSS attack
I'm personally using the localStorage to store token because it is convenient. React has built-in XSS prevention and you can additionally switch on CSP (Content Security Protection). I write the article about my approach: https://saasitive.com/tutorial/react-token-based-authentication-django/ - the httpOnly vs localStorage discussion is at the end of the post. There is also full tutorial how to start SaaS app with Django and React (link).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…